5

このコード:

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

いくつかのエラーを返します:

Set-ItemProperty : プロパティ System.Boolean IsReadOnly=False は存在しません。行:1 文字: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 に「ReadOnly」を設定すると失敗します。

この使用を処理するには:

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