Active Directory PowerShell Module
A quick follow up from an old post, there some bonus feature with the Active Directory module. This module is not as efficient as the ADSI objects shown in the post but hereunder some example of bonus features.
Active Directory PowerShell Module Prerequisites
This module has three requirements :
- Windows Server 2008R2 or higher as Domain Controller
- Windows Server 2008R2 or Windows 7 or higher as a PowerShell host
- Remote Server Administration Tools
You can also install Active Directory Management Gateway Services on older version of Windows Server that will provide the same features as Active Directory Web Services.
Active Directory PSDrive
When the module is imported, it will create you a PowerShell drive that will allow you to browse the domain just like you do with your logical drive or your local registry hives:
Get-PSDrive Import-Module ActiveDirectory Get-PSDrive Set-Location ad:\
Active Directory ACL
You can see the ACL with Get-Acl:
Get-Acl '.\DC=D2K12R2,DC=local' | Select-Object -ExpandProperty Access | Out-GridView
List Users in a Organizational Unit
You can list the users in an OU with a standard Get-ChildItem:
Get-ChildItem -Path 'OU=Users,OU=Star Wars,OU=Production,DC=D2K12R2,DC=local'
Note: The users came from this post:
You can list sites with a Get-ChildItem like for users, you just need to change the path. Indeed, the Active Directory sites are stored in the partition configuration:
Get-ChildItem -Path 'CN=Sites,CN=Configuration,DC=D2K12R2,DC=local'
You move move users from an organizational unit to another one with:
Move-Item -Path 'CN=Junk7,OU=Test,DC=D2K12R2,DC=local' -Destination 'OU=Trash,OU=Test,DC=D2K12R2,DC=local'
Note: This will work with computers and groups too.
You can delete a user just like a file on your disk:
Remove-Item -Path 'CN=Junk7,OU=Trash,OU=Test,DC=D2K12R2,DC=local'
This will work on other types of objects too.
There is a lot of cmdlets that you can use, actually, there is 147 cmdlets in this module in Windows Server 2012R2. Each new version of Windows Server brings some new cmdlets, hereunder a list of them from a Windows Server 2012R2 server: