10 tips for Active Directory administration with PowerShell
Table of Contents
- Getting started managing Active Directory with PowerShell
- Install the PowerShell module for Active Directory administration
- Activate PowerShell remoting and fix connection problems
- Display PowerShell modules and cmdlets for Active Directory administration
- Retrieving Active Directory data
- Testing the requirements for the operation of Active Directory
- Installing a domain controller
- Creating AD objects with Powershell
- Querying and setting deletion protection with PowerShell

For those who frequently need to perform tasks in Active Directory, such as creating and managing users and groups or troubleshooting, PowerShell provides a number of cmdlets that make life easier. Also, the administration of domains and the infrastructure in Active Directory can be solved optimally with the PowerShell. It is not about PowerShell replacing the other management tools. The PowerShell complements the administration tools of Active Directory and is an additional help.
Getting started managing Active Directory with PowerShell
Install the PowerShell module for Active Directory administration

Figure 1: Screenshot of the Settings app on Windows 10 with the “Optional Features” tab open
On servers the installation can be done by adding the remote administration tools for Active Directory in the Server Manager or the Windows Admin Center (Figure 2). Here you can find the PowerShell module for Active Directory in the Remote Server Administration Tools > Role Administration Tools > AD DS- and AD LDS Tools.
On Windows servers, the Active Directory management tools can also be installed from the PowerShell. This is done by using the Install-WindowsFeature RSAT-AD-PowerShell command.

Figure 2: Installing Remote Administration Tools on Servers
Activate PowerShell remoting and fix connection problems
If the connection does not work, you can check in the command prompt or PowerShell with winrm enumerate winrm/config/listener whether a listener with port 5985 is active and bound to all IP addresses of the server.

Figure 3: Checking the remote connection for PowerShell on Windows servers
Display PowerShell modules and cmdlets for Active Directory administration

Figure 4: Displaying the Active Directory administration cmdlets
Retrieving Active Directory data
Get-ADDomain | Select InfrastructureMaster, RID-Master, PDCEmulator

Figure 5: Displaying the data of individual AD domains using Get-ADDDomain
Schema Master and Domain Name Master are unique per AD forest. This information can be displayed again by using Get-ADForest:
Get-ADForest | Select-Object DomainNamingMaster, SchemaMaster
Operation Master roles can be moved to other domain controllers in the PowerShell. The equivalent cmdlet is
Move-ADDirectoryServerOperationMasterRole
Get-Help Move-ADDirectoryServerOperationMasterRole displays the full syntax and some examples of the cmdlet (this applies generally to all cmdlets in PowerShell).
Testing the requirements for the operation of Active Directory
- Test-ADDSDomainControllerInstallation:Enables you to test the prerequisites for installing a domain controller.
- Test-ADDSDomainControllerUninstallation
- Test-ADDSDomainInstallation: tests the prerequisites for installing a new domain in Active Directory
- Test-ADDSForestInstallation: Tests the prerequisites for the installation of a new forest domain in Active Directory
- Test-ADDSReadOnlyDomainControllerAccountCreation
To run the tests, passwords must be entered at various places. However, the respective cmdlet accepts them only as secure input. An example of the command is:
Test-ADDSDomainControllerInstallation -DomainName -SafeModeAdministratorPassword (Read-Host -Prompt Kennwort -AsSecureString)
Installing a domain controller
Invoke-Command {Install-ADDSDomainController -DomainName -Credential (Get-Credential) -ComputerName
Creating AD objects with Powershell
A list of commands to delete objects can be displayed with Get-Command Remove-Ad*. Changes to Active Directory objects are made by using Set- cmdlets. A list is of them is displayed by using Get-Command Set-Ad*.
Querying and setting deletion protection with PowerShell
Get-ADObject ‹DN of object› -Properties ProtectedFromAccidentalDeletion
The deletion protection can be activated with :
Set-ADObject ‹DN of object› -ProtectedFromAccidentalDeletion $true
If you want to deactivate the deletion protection, you can again set the option “$false”. If no objects are to be protected but organizational units, the cmdlets Get-ADOrganizationalUnit and Set-ADOrganizationalUnit are used.
Related posts
5 min read
AD objects and more — How to search in properties of complex objects
Feb 3, 2022 by Tibor Soós
About the author:
Thomas Joos is a freelance IT consultant and has been working in IT since 1992. He has published more than 90 practical reference books and writes for numerous IT publications such as c’t, PC Magazin, PC Welt, IT Administrator, Computerwoche and Heise Security.
Latest posts:
- Working efficiently with the PowerShell pipeline: A guide for administrators (1)
- Licensing with Microsoft Graph PowerShell
- ScriptRunner Ultimate Edition 6 – AI‑powered scripting
- How to connect to Exchange Online with certificate based authentication (CBA)
- Get-View in PowerCLI – How to manage your VMware infrastructure more efficiently (part 3)