Get-ChildItem : *A parameter cannot be found that matches parameter name 'Directory'*
エラーメッセージが表示されます。下記のスクリプトが使用されています。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
Chirsh、お返事に感謝を。 'Readonly'エラーメッセージを解決するにはどうすればよいですか? Get-ChildItem:パス 'C:\ play \ test'が存在しないため見つかりません。 C:\ Play \ BackupCompress.ps1:36 char:29 + $ Directories = Get-ChildItem <<<< -Path $ BackupDir | ?{$ _。PSIsContainer} + CategoryInfo:ObjectNotFound:(C:\ play \ test:String)[Get-ChildItem]、ItemNotFoundException + FullyQualifiedErrorId:PathNotFound、Microsoft.PowerShell.Commands.GetChildItemCommandGet-ChildItem:パラメータは使用できません。パラメータ名 'ReadOnly'と一致するものが見つかりました。 C:\ Play \ BackupCompress.ps1:45 char:66 – kumar
子アイテムのIsReadOnlyプロパティを使用することができます。 '$ SubFiles = Get-ChildItem -Path $ Directory -Recurse | Where-Object {$ _。IsReadOnly} ' –