5

这段代码:

Get-ChildItem $targetConfig -Recurse | Set-ItemProperty -Name IsReadOnly -Value $false

返回几个错误:

Set-ItemProperty:属性 System.Boolean IsReadOnly=False 不存在。在 line:1 char:56 + Get-ChildItem $targetConfig -Recurse | Set-ItemProperty <<<< -Name IsReadOnly -Value $false + CategoryInfo : ReadError: (System.Boolean IsReadOnly=False:PSNoteProperty) [Set-ItemProperty], IOException + FullyQualifiedErrorId : SetPropertyError,Microsoft.PowerShell.Commands.SetItemPropertyCommand

这个错误是什么意思?

4

1 回答 1

9

它发生是因为:

Get-ChildItem $targetConfig -Recurse

返回 DirectoryInfo 和 FileInfo。并且 Set-ItemProperty 无法为 DirectoryInfo 设置“只读”。

要处理这种使用:

Get-ChildItem $targetConfig -Recurse |
    Where-Object {$_.GetType().ToString() -eq "System.IO.FileInfo"} |
    Set-ItemProperty -Name IsReadOnly -Value $false
于 2013-01-16T21:17:53.220 回答