PowerShell has become an essential tool for Windows Server and Active Directory management. Here’s a guide to some of the most useful PowerShell commands for these types of environments that are guaranteed to make both your life and management easier.
Active Directory Management
User Management
- Get User Information:
Get-ADUser username -Properties *
This command retrieves all properties of a specific user.
- List Users in an OU:
Get-ADUser -SearchBase "OU=ADPRO Users,dc=ad,dc=atyxit.com" -Filter *
This command lists all users in a specific Organizational Unit.
- Create a New User:
New-ADUser -Name "Full Name" -SamAccountName "username" -UserPrincipalName "[email protected]" -Path "OU=Users,DC=domain,DC=com"
Group Management
- Add User to a Group:
Add-ADGroupMember SecurityGroupName -Members Username01
- Remove User from a Group:
Remove-ADGroupMember SecurityGroupName -Members Username01
- Create a New Security Group:
New-ADGroup -Name "GroupName" -GroupScope Global -GroupCategory Security
Computer Management
- Get Computer Information:
Get-ADComputer ComputerName -Properties *
- Create a New Computer Object:
New-ADComputer -Name "ComputerName" -SamAccountName "ComputerName" -Path "OU=Computers,DC=Domain,DC=com"
Windows Server Management
- Get Running Processes:
Get-Process | Sort-Object CPU -Descending | Select-Object -First 5
This command lists the top 5 processes using the most CPU.
- Restart a Service:
Restart-Service DHCP
This command restarts the DHCP service.
- List Directory Contents:
Get-ChildItem c:\directory -Recurse
This command lists all items in a directory and its subdirectories.
- Remove Files or Folders:
Remove-Item C:\ToBeDeleted -Recurse
This command deletes a folder and its contents.
- Restart a Computer:
Restart-Computer
This command reboots the local system.
Active Directory Information Gathering
- Get Domain Information:
Get-ADDomain
This command displays information about the current domain.
- Get Forest Information:
Get-ADForest
This command shows details about the Active Directory forest.
- List All Active Directory Cmdlets:
Get-Command -Module ActiveDirectory
This command displays all available Active Directory-related cmdlets.
Best Practices
- Always use the
-WhatIf
parameter before executing commands that make changes to ensure you understand the impact. - Use
Get-Help
to learn more about any cmdlet. For example:
Get-Help Move-ADDirectoryServerOperationMasterRole -Detailed
- When working with multiple objects, consider using the
ForEach-Object
cmdlet for batch operations. - Use PowerShell ISE or Visual Studio Code for script development, as they provide IntelliSense and debugging capabilities.
By mastering these useful PowerShell commands, IT administrators can significantly improve their efficiency in managing Windows Servers and Active Directory environments. Remember to always test commands in a non-production environment first and ensure you have the necessary permissions before executing them.
For some more useful powershell commands, check out the links below!
https://devblogs.microsoft.com/scripting/table-of-basic-powershell-commands/
https://www.scriptrunner.com/en/blog/administer-active-directory-with-powershell/
https://learn.microsoft.com/en-us/powershell/module/activedirectory/?view=windowsserver2025-ps
ATYXIT is a security-first Business IT Solutions Provider and Chicago Cloud Provider. We excel in supporting and evolving company networks. Our technical support, technology consulting, project management, cyber security and IT strategy services make us the ideal IT resource for local small and medium sized businesses.
Reach out today if you need any assistance with your business technology!