I have an ICACLS command running within a powershell script. The script creates a new folder on a server share, creates a new security group in AD and then runs ICACLS to provision the folder. When I execute the function, sometimes it works and sometimes it doesn't. In testing, only 50% of the time does the ICACLS command work successfully.
New-ADGroup -Name "Group Name" -GroupCategory Security -GroupScope Global -SamAccountName "Group Name" -Description "Security Group" -Path "OU=Accounts,DC=Contoso,DC=COM" New-Item -Path "\\Server1\ServerShare\" -Name "Group Share" -ItemType directory icacls "\\Server1\ServerShare\Group Share" /Inheritance:r /T /Grant:R "Group Name"
icacls : Group Name: No mapping between account names and security IDs was done. + CategoryInfo :NotSpecified: (Group Name...y IDs was done. :String) , RemoteException + FullyQualifiedErrorID : NativeCommandError