I have a script that creates two groups, a hand full of folders, and sets permissions on those folders. In my testing environment all of these processes work without issue but in my production environment I run into a problem. Setting the permissions on the folders fail since the groups I created have not replicated through all 8 of my domain controllers. Can have PowerShell work with only one of the DC's so I don't have to wait for the replication? Should I put the script to sleep for X seconds? Or is there some way to see if the groups are on all the DC's or at least on the one I am working?
This is how I am making the groups:
New-ADGroup -Name $Admin_GRP -path "OU=Users,OU=Sandbox,DC=test,DC=local" -GroupScope Global
New-ADGroup -Name $User_GRP -path "OU=Users,OU=Sandbox,DC=test,DC=local" -GroupScope Global
This is how I am setting the permissions on one of the folders:
#Set permissions on root directory
$ACL = Get-Acl $PathToFolder
#For Admin
$Permission = $Admin_GRP,"Write,ReadAndExecute,Synchronize,DeleteSubdirectoriesAndFiles","Allow"
$Access_Rule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
$ACL.AddAccessRule($Access_Rule)
$ACL | Set-Acl $PathToFolder
#For Users
$Permission = $User_GRP,"ReadAndExecute,Synchronize","Allow"
$Access_Rule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
$ACL.AddAccessRule($Access_Rule)
$ACL | Set-Acl $PathToFolder