Powershell Get-ChildItem:找不到与参数名称';目录';

Powershell Get-ChildItem:找不到与参数名称';目录';,powershell,Powershell,我正在获取Get ChildItem:*找不到与参数名称“Directory”匹配的参数*错误消息,下面是使用的脚本,请帮助我查找问题 脚本: Function Clear-ReadOnlyFiles([string]$path) { "Clearing readonly attribute from files in $path" New-Variable -Name read_only -Value 1 -Option readonly Get-ChildItem -Path $pa

我正在获取
Get ChildItem:*找不到与参数名称“Directory”匹配的参数*
错误消息,下面是使用的脚本,请帮助我查找问题

脚本:

Function Clear-ReadOnlyFiles([string]$path)
{
  "Clearing readonly attribute from files in $path"
 New-Variable -Name read_only -Value 1 -Option readonly
 Get-ChildItem -Path $path |
 Where-Object { $_.attributes -match 'readonly' } |
 ForEach-Object {
   $_.attributes = $_.attributes -Bxor $read_only }
}#end Clear-ReadonlyFiles


$ZipCmd     = "{0}\7za.exe" -f $BackupDir
$ZipCmdArgs     = "-sdel"

# Grab Directories in Location
$Directories = Get-ChildItem -Path $BackupDir -Directory

# Cycle Through and Launch 7za to Compress
# Check if Archive Exists - If yes, delete source folder
ForEach ($Directory in $Directories)
{
    $Source  = "{0}\{1}" -f $BackupDir,$Directory.Name
    $Archive = "{0}.7z" -f $Source

    # Clear Read-Only Attribute on Folder
    $SubFiles = Get-ChildItem -Path $Directory -Recurse -ReadOnly
    ForEach ($SubFile in $SubFiles) {
        $SubFile.IsReadOnly = $False
    }

    #If ($Directory.IsReadOnly -eq $True) { $Directory.set_IsReadOnly($False) }

    $AllArgs = @('a', $ZipCmdArgs, $Archive, $Source);

    & $ZipCmd $AllArgs
}
Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'.
At C:\Play\BackupCompress.ps1:35 char:57
+ $Directories = Get-ChildItem -Path $BackupDir -Directory <<<< 
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Get-ChildItem : A parameter cannot be found that matches parameter name 'ReadOnly'.
At C:\Play\BackupCompress.ps1:45 char:66
+     $SubFiles = Get-ChildItem -Path $Directory -Recurse -ReadOnly <<<< 
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Property 'IsReadOnly' cannot be found on this object; make sure it exists and is settable.
At C:\Play\BackupCompress.ps1:47 char:18
+         $SubFile. <<<< IsReadOnly = $False
    + CategoryInfo          : InvalidOperation: (IsReadOnly:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
错误消息:

Function Clear-ReadOnlyFiles([string]$path)
{
  "Clearing readonly attribute from files in $path"
 New-Variable -Name read_only -Value 1 -Option readonly
 Get-ChildItem -Path $path |
 Where-Object { $_.attributes -match 'readonly' } |
 ForEach-Object {
   $_.attributes = $_.attributes -Bxor $read_only }
}#end Clear-ReadonlyFiles


$ZipCmd     = "{0}\7za.exe" -f $BackupDir
$ZipCmdArgs     = "-sdel"

# Grab Directories in Location
$Directories = Get-ChildItem -Path $BackupDir -Directory

# Cycle Through and Launch 7za to Compress
# Check if Archive Exists - If yes, delete source folder
ForEach ($Directory in $Directories)
{
    $Source  = "{0}\{1}" -f $BackupDir,$Directory.Name
    $Archive = "{0}.7z" -f $Source

    # Clear Read-Only Attribute on Folder
    $SubFiles = Get-ChildItem -Path $Directory -Recurse -ReadOnly
    ForEach ($SubFile in $SubFiles) {
        $SubFile.IsReadOnly = $False
    }

    #If ($Directory.IsReadOnly -eq $True) { $Directory.set_IsReadOnly($False) }

    $AllArgs = @('a', $ZipCmdArgs, $Archive, $Source);

    & $ZipCmd $AllArgs
}
Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'.
At C:\Play\BackupCompress.ps1:35 char:57
+ $Directories = Get-ChildItem -Path $BackupDir -Directory <<<< 
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Get-ChildItem : A parameter cannot be found that matches parameter name 'ReadOnly'.
At C:\Play\BackupCompress.ps1:45 char:66
+     $SubFiles = Get-ChildItem -Path $Directory -Recurse -ReadOnly <<<< 
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Property 'IsReadOnly' cannot be found on this object; make sure it exists and is settable.
At C:\Play\BackupCompress.ps1:47 char:18
+         $SubFile. <<<< IsReadOnly = $False
    + CategoryInfo          : InvalidOperation: (IsReadOnly:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
Get ChildItem:找不到与参数名称“Directory”匹配的参数。
在C:\Play\BackupCompress.ps1:35 char:57

+$Directories=Get ChildItem-Path$BackupDir-Directory我相信目录开关是在PowerShell 3.0中添加的。在旧版本中,您需要检查每个子项的PSIsContainer属性,如果该项是目录,则该属性为true:

$Directories = Get-ChildItem -Path $BackupDir | Where-Object { $_.PSIsContainer }

-Directory是一个条件参数,仅适用于提供程序为“FileSystem”的路径。它位于此页上,但不在上

键入以下内容时,请确保显示正确的提供程序:

Get-Item $BackupDir | Select-Object -Property PSProvider

Chirsh,谢谢你的回复。如何解决“只读”错误消息?Get-ChildItem:找不到路径“C:\play\test”,因为它不存在。在C:\Play\BackupCompress.ps1:36 char:29+$Directories=Get ChildItem,您应该能够使用子项的IsReadOnly属性来执行此操作:
$SubFiles=Get ChildItem-Path$Directory-Recurse |其中对象{$\ IsReadOnly}