Bite Size Bytes

Small coding solutions to big problems


Navigate AD with Powershell

Some environments have multiple domains in a single Active Directory forest. Working with Powershell in the same domain as your user account is easy, but what do you do when you need to run Powershell commands in one of the other domains? Change context. Powershell can traverse AD as a file system, and this allows an easy way to change the context for your script. Keep in mind, that to be able to load the AD Powershell module, you need to install the RSAT tools on the workstation that you are using to run your commands.

The following code will mount your current domain as a drive:

Import-Module ActiveDirectory

New-PSDrive -Name "ADDomain" -PSProvider ActiveDirectory -root ""

cd ADDomain:

cd "DC=domain,DC=com"

If you want to mount a different domain in the forest, you need to point to a domain controller for the desired domain:

New-PSDrive -Name "OtherDomain" -PSProvider ActiveDirectory -root "" -server OtherDC.altdomain.com

Just remember, the Powershell instance that you are running must have permissions to access AD in the other domain. Typically in AD, domains in the same forest have trust relationships setup and that means you can use RunAs to open Powershell as an admin account from the alternate domain if your account doesn’t have admin privileges.



Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About Me

As a seasoned IT professional, I have developed an extremely well-rounded breadth and depth of knowledge and an exceptional ability to decipher and communicate complex issues. I have years of proven experience in IT leadership roles, security auditing, digital forensics, and overseeing development of custom applications, rounded out with a Bachelor of Science degree in Information Technology emphasizing Software Development. Over the course of my career, I have successfully held certifications as a GIAC Certified Incident Handler (GCIH), as well as CIW, CompTIA, and assorted Microsoft programming and networking certs. I have presented at the 2019 CETPA Conference in Anaheim and the 2021 CITE Conference in Sacramento.

Codementor badge