This code:
Get-ChildItem $targetConfig -Recurse | Set-ItemProperty -Name IsReadOnly -Value $false
Returns several errors:
Set-ItemProperty : Property System.Boolean IsReadOnly=False does not exist. At 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
What this errors means?
It happens because:
Get-ChildItem $targetConfig -Recurse
Return both DirectoryInfo and FileInfo. And Set-ItemProperty fails on setting "ReadOnly" for DirectoryInfo.
To handle this use:
Get-ChildItem $targetConfig -Recurse |
Where-Object {$_.GetType().ToString() -eq "System.IO.FileInfo"} |
Set-ItemProperty -Name IsReadOnly -Value $false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With