Active Directory

Connect to the Active Directory Drive in PowerShell

How do I connect to the AD drive using PowerShell?

The Active Directory drive (AD:) in PowerShell gives administrators an easy way to explore AD from the command line, in much the same way you would list the directory contents of a hard disk using the DIR command in DOS. Let’s see how to connect to the AD drive and the commands used to navigate through it.

Connecting to the AD drive

  • Log in to Windows Server 2012 with a user account that has permission to access AD and open PowerShell from the icon on the desktop Taskbar.
  • Type Import-Module ActiveDirectory in the PowerShell window and press Enter.
  • Now we need to set the working location to the AD drive. Type Set-Location AD: and press Enter. Notice that the PowerShell prompt now changes to PS AD: >.
  • Type DIR and press Enter.

Navigating down

You’ll see a list of the forest’s partitions. To do anything useful, we need to connect to the domain partition using the set-location cmdlet.

  • Type Set-Location “<distinguished name>” and press Enter.

The distinguished name (DN) of your domain can be seen in the output of the previous DIR command. The DNS name of my Active Directory domain is ad.contoso.com, therefore the domain’s DN is dc=ad,dc=contoso,dc=com. So the command should look like Set-Location “dc=ad,dc=contoso,dc=com”. Again the PowerShell prompt will change, in this example to PS AD:\dc=ad,dc=contoso,dc=com>.

  • To drill further down into the AD hierarchy, use the Set-Location cmdlet to change the working location to the Users container. Type Set-Location “cn=users” and press Enter.

Connecting to the AD drive using PowerShell

Sponsored Content

What is “Inside Microsoft Teams”?

“Inside Microsoft Teams” is a webcast series, now in Season 4 for IT pros hosted by Microsoft Product Manager, Stephen Rose. Stephen & his guests comprised of customers, partners, and real-world experts share best practices of planning, deploying, adopting, managing, and securing Teams. You can watch any episode at your convenience, find resources, blogs, reviews of accessories certified for Teams, bonus clips, and information regarding upcoming live broadcasts. Our next episode, “Polaris Inc., and Microsoft Teams- Reinventing how we work and play” will be airing on Oct. 28th from 10-11am PST.

Note that if you want to change the working location to an Organizational Unit (OU) instead of a container, change cn to ou. For example, to connect to the HR OU, the command might look like Set-Location “ou=hr users”.

Moving up

In exactly the same way you navigate back up a directory tree in DOS, you can use the set-location command to move back up a level. For example, to move from cn=users,dc=ad,dc=contoso,dc=com up one level to dc=ad,dc=contoso,dc=com, type set-location followed by two dots in the PowerShell window, like so: set-location ..

Saving a directory location

If you want to move in and out of the AD drive, or move around the AD drive but need to frequently return to a particular location, you can use the push-location and pop-location cmdlets:

  • To save the current working location, type Push-Location and press Enter.
  • Now let’s return to the C drive by typing Set-Location C: and press Enter.
  • To quickly return to the previously saved location, type Pop-Location and press Enter.

Related Topics:

IT consultant, Contributing Editor @PetriFeed, and trainer @Pluralsight. All about Microsoft, Office 365, Azure, and Windows Server.
External Sharing and Guest User Access in Microsoft 365 and Teams

This eBook will dive into policy considerations you need to make when creating and managing guest user access to your Teams network, as well as the different layers of guest access and the common challenges that accompany a more complicated Microsoft 365 infrastructure.

You will learn:

  • Who should be allowed to be invited as a guest?
  • What type of guests should be able to access files in SharePoint and OneDrive?
  • How should guests be offboarded?
  • How should you determine who has access to sensitive information in your environment?

Sponsored by:

 
Live Webinar: Active Directory Security: What Needs Immediate Priority!Live on Tuesday, October 12th at 1 PM ET

Attacks on Active Directory are at an all-time high. Companies that are not taking heed are being punished, both monetarily and with loss of production.

In this webinar, you will learn:

  • How to prioritize vulnerability management
  • What attackers are leveraging to breach organizations
  • Where Active Directory security needs immediate attention
  • Overall strategy to secure your environment and keep it secured

Sponsored by: