Script repository
The script creates a folder for an AD group and grants the group full access permissions for the folder. To execute the script, create a business rule, custom command or scheduled task configured for the Group object type.
In the script, the $folderPath variable specifies a path to the folder that will be created.
$folderPath = "\\Server\Share\%name%" # TODO: modify me
# Create folder
try
{
$folder = New-Item -Path $folderPath -ItemType Directory -ErrorAction Stop
}
catch
{
$Context.Cancel("An error occurred while creating a folder for the group. Error: " + $_.Exception.Message)
return
}
# Grant Full Access permissions to the group.
$aclObj = Get-Acl $folder
$groupSidBinary = $Context.TargetObject.Get("objectSid")
$groupSid = New-Object System.Security.Principal.SecurityIdentifier($groupSidBinary, 0)
$acl = New-Object System.Security.AccessControl.FileSystemAccessRule($groupSid, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
$aclObj.AddAccessRule($acl)
Set-Acl -path $folder $aclObj
Comments 0
You must be signed in to comment.