Use Get-Acl and Set-Acl with a specified Active Directory domain controller using PSDrive
When you use Active Directory commands such as Get-ADObject and Get-ADUser you'll notice there is a -Server switch you can use to specify a domain controller to use for the operation.
This switch isn't however available for the Get-Acl and Set-Acl commands. You may want to use a specific domain controller for example if you're setting the security descriptor of an object you've just created and the object may not have replicated yet.
Get-Acl and Set-Acl however use the Active Directory PSDrive AD: which performs a serverless bind when you run the Import-Module ActiveDirectory command as you can see in the screenshot.
PSDrive created |
Running the command Get-PSDrive AD displays the following, showing that the default AD: drive does not have a server specified.
No Server Specified |
Changing the default AD: drive probably isn't a good idea however we can create a new drive.
New-PSDrive -Name AD2 -PSProvider ActiveDirectory -Server "demo2022-dc02" -Scope "Script" -root "//RootDSE/"
And as we can see we can now see a server specified.
Server Specified |
We can now issue the Get-Acl command using the new AD2 drive
Get-Acl -Path "AD2:DC=demo2022,DC=int" | SELECT *
Get-Acl output |
You can easily prove that the command is using the specific domain controller by pausing that domain controller (if it's a VM) and the command will fail.
Please comment if this has been helpful or if you have any questions.
ReplyDelete