Microsoft provided several Active Directory PowerShell cmdlets with Windows Server 2008 R2 (and newer) which greatly simplify tasks which previously required putting together lengthy lines of code involving ADSI.
On a Windows client, install the Remote Sever Administration Tools (RSAT) and ensure the Active Directory PowerShell module is installed.
On a Windows server (2008 R2 or newer), run the following commands in a PowerShell console (as an Adminsitrator):
Import-Module ServerManager ; Add-WindowsFeature RSAT-AD-PowerShell
Here’s my (poor) ADSI example:
$UserID = “JoeUser” $root = [ADSI]'' $searcher = new-object System.DirectoryServices.DirectorySearcher($root) $searcher.filter = "(&(objectClass=user)(sAMAccountName= $UserID))" $user = $searcher.findall() $user
Here’s the same thing with the AD PowerShell cmdlet:
Import-module ActiveDirectory
$UserID = “JoeUser”
Get-ADUser $UserID –property *
Note that with PowerShell version 3 and newer, you don’t need to run the first line since Powershell will identify the necessary module and auto load it.
Once you have the Active Directory PowerShell module loaded, you can do cool stuff like browse AD like a file system

Finding Useful Commands (Cmdlets):
Discover available PowerShell modules: Get-Module -ListAvailable
Discover cmdlets in a PowerShell module: Get-Command -module ActiveDirectory
PowerShell AD Module Cmdlets:
- Windows Server 2008 R2: 76 cmdlets
- Windows Server 2012: 135 cmdlets
- Windows Server 2012 R2: 147 cmdlets
- Windows Server 2016: 147 cmdlets
(Get-Command -module ActiveDirectory).count
Finding Active Directory Flexible Master Single Operation (FSMO) Roles:
Active Directory Module:
-
(Get-ADForest).SchemaMaster
-
(Get-ADForest).DomainNamingMaster
-
(Get-ADDomain).InfrastructureMaster
-
(Get-ADDomain).PDCEmulator
-
(Get-ADDomain).RIDMaster
.NET Calls:
-
([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).SchemaRoleOwner
-
([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).NamingRoleOwner
-
([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).InfrastructureRoleOwner
-
([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).PdcRoleOwner
-
([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).RidRoleOwner
Active Directory PowerShell Module Cmdlet Examples:



Recent Comments