Posted On August 29, 2019

PowerShell: Grant Domain Admins Access to Directories

kimconnect 0 comments
blog.KimConnect.com >> Codes >> 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 *

Related Post

Basic HTML and HTML5: Use HTML5 to Require a Field

<h2>CatPhotoApp</h2><main><p>Click here to view more <a href="#">cat photos</a>.</p><a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying…

Windows: Force Dedicated RAM to Integrated Graphics

Please be advised that the following instructions will only be effective for Windows computers with…

PowerShell: Fix All VMs CPU Compatibility Setting

# fixAllVmCpuCompatibility.ps1 # version 0.01 function getHyperVHostsInForest{ function includeRSAT{ $ErrorActionPreference='stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #$rsatWindows7x32='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x86-RefreshPkg.msu' $rsatWindows7x64='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x64-RefreshPkg.msu'…