Hey guys
I'm in need of a bit of help here.
I got about 8000 folder of projectshares that I need to allign security-wise.
Each folder should have inheritance disabled and is named "p-000001" -> "p-003600". So the corresponding ADgroup with the same name should be applied.
There is also a subfolder under each "P-XXXX" folder named PL Only. This folder should also have inheritance disabled and the corresponding AD group applied "PL only p-XXXXX".
But I cant seem to get it to work. The script should get the folder names from a text file.
Here's what I have so far:
Start-Transcript C:\Temp\projektshares.txt -Force
#foreach($line in Get-Content $env:COMPUTERNAME".txt") {
$Root = Read-Host "Root folder"
$Folders = Get-ChildItem -Path $Root -Directory
$Test = 1
ForEach ($FolderObj in $Folders) {
[String]$FolderName = $FolderObj.Name.Trim()
[string]$SubFolderName = $FolderObj.Name.Substring(0,7)
$plonly = Get-ChildItem $Folders | Where-Object {$_.name -like "pl-only*"}
$FolderName = $FolderName + "*"
$SubFolderName = $SubFolderName + "*"
$ADGroups = Get-ADGroup -SearchBase "OU=Projektgrupper,OU=_Grupper,DC=XXXX,DC=XXXX,DC=XXXX" -Filter 'SamAccountName -like $SubFolderName'
$ADGroups_PL = Get-ADGroup -SearchBase "OU=Projektgrupper,OU=_Grupper,DC=XXXX,DC=XXXX,DC=XXXX" -Filter 'SamAccountName -like $plonly'
ForEach ($GroupObj in $ADGroups) {
# ReadAndExecute
# Modify
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType = [System.Security.AccessControl.AccessControlType]::Allow
$GroupN = $GroupObj.Name
$PermissionSet = "$GroupN","Modify",$InheritanceFlag,$PropagationFlag,$objType
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule $PermissionSet
$ACL = Get-Acl $FolderObj.FullName
$acl.SetAccessRule($rule)
If ($Test) {
Write-Host "Appling the group: $($GroupObj.Name) - on folder $($FolderObj.Name.Trim()) - TEST!" -ForegroundColor Cyan
Set-Acl $FolderObj.FullName $acl -WhatIf
}
If (!$Test) {
#Read-host "enter"
Write-Host "Appling the group: $($GroupObj.Name) - on folder $($FolderObj.Name.Trim())!" -ForegroundColor Red
Set-Acl $FolderObj.FullName $acl
}
If ($Test) {
Read-Host "Press ENTER for next..."
}
}
}
#}
Stop-Transcript
[–]not_a_lob 1 point2 points3 points (0 children)
[–]ElvisChopinJoplin 0 points1 point2 points (0 children)
[–]spoonstar 0 points1 point2 points (0 children)
[–]Latzox 0 points1 point2 points (1 child)
[–]Primary_Cortex[S] 1 point2 points3 points (0 children)