PowerShell: Grant Domain Admins Access to Directories

Snippet:
# Messing around
$shareDrives=@("E","F","G","I","J","N",'O','Q','R','S','T','U','V','W','Z','Y');
$subdomain=(net config workstation) -match 'Workstation domain\s+\S+$' -replace '.+?(\S+)$','$1';
$domainadmins="$subdomain`\Domain Admins";
$shareDrives | %{"Add-NTFSAccess –Path '$_`:\' –Account $domainadmins –AccessRights Full -ErrorAction SilentlyContinue";}

# The real deal (will take a long time to process)
# Limitations: a) it will not modify ACLs of root volumes b) will not modify items where "SYSTEM" or "Administrators" have no access
$shareDrives=@("E","F","G","I","J","N",'O','Q','R','S','T','U','V','W','Z','Y');
$subdomain=(net config workstation) -match 'Workstation domain\s+\S+$' -replace '.+?(\S+)$','$1';
$domainadmins="$subdomain`\Domain Admins";
$shareDrives | %{Add-NTFSAccess –Path "$_`:\Shares" –Account $domainadmins –AccessRights Full -ErrorAction SilentlyContinue;}
Sample Output:
Add-NTFSAccess –Path 'E:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'F:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'G:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'I:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'J:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'N:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'O:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'Q:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'R:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'S:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'T:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'U:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'V:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'W:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'Z:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue
Add-NTFSAccess –Path 'Y:\' –Account WORKGROUP\Domain Admins –AccessRights Full -ErrorAction SilentlyContinue

Leave a Reply

Your email address will not be published. Required fields are marked *