I need some help! Heres the scenerio; I need to make all Files & Folders on one of our File Shares Read-Only except for 4 Sub-Folders accross many different folders on the share. All Level 1 Sub-Folders have same 4 folders within and those permissions need to be preserved while all others need to be set to Read-Only.
I wrote up the script below and all is working fine to Exclude the 4 Sub-Folders when setting to Read-Only, but when I add the -Recurse switch to Get-ChildItem the Exclude list is ignored for some reason. What am I doing wrong?
$Path = C:\Users\Username\Downloads\*
$Exclude = "\Sub-Folder1\*","\Sub-Folder2\*","\Sub-Folder3\*","\Sub-Folder4\*"
$Folders = Get-ChildItem -Path $Path -Recurse -Exclude $Exclude
ForEach ($Folder in $Folders) {
Set-ItemProperty -Path $Folder -Name IsReadOnly -Value $True -Exclude $Exclude
Write-Host folder:$Folder IsReadOnly: $Folder.IsReadOnly
}
I was expecting that the Attribute would be changed on all Folders and Files Except for what I placed in the Exclude list.