MicrosoftWindows Server 2016Windows Server 2019Windows Server 2022Windows Server 2025

Common PowerShell Commands | Every Admin Must Know

30 Important PowerShell Commands To Manage Your Active Directory

Explore the 30 Most Important and Common PowerShell Commands

Every Admin must know about Important and common PowerShell commands to manage their IT stuff

It is important to get the collection of Important PowerShell commands so you can use them when it is required.

Whether you are a beginner or looking to refresh your skills.

This article will help you cover the most commonly used commands to manage your systems

Like user creation in Active Directory, listing users and groups, listing group policy, exporting results to a CSV file, or emailing them as an attachment.

In this article, we will explore about 30 Important and common PowerShell commands helpful in managing your systems in a network joined with a Windows Server 2025 domain controller.

 

PowerShell Commands to Create, Modify, & List Users in AD

To list all users in Active Directory, you can use the following cmdlet

Get-ADUser -Filter *

Same if you want these results to export in a CSV file, run the following cmdlet.

Get-ADUser -Filter * | Export-Csv -Path c:\reports\users.csv

Note: Make sure you have a folder named reports created in the C: drive to provide the correct path.

Powershell commands csv result

Therefore, to create a new user by the name of Peter in your Active Directory, use the following PowerShell cmdlet

$splat = @{

    Name = 'Peter'

    AccountPassword = (Read-Host -AsSecureString 'AccountPassword')

    Enabled = $true

}

New-ADUser @splat

You just have to put the password for the user, and it will create and enable the user by the name of Peter.

To modify the user’s AD Attributes, you have to use the cmdlet

This will set the title of user Peter as an IT Manager

Set-ADUser -Identity Peter -Title "IT Manager"

cmdlet to change job title

To disable the user in your Active Directory, run the following cmdlet

Disable-ADAccount -Identity peter

Therefore, to enable the AD user, run the following cmdlet

Enable-ADAccount -Identity peter

To unlock the locked user account from Active Directory, run the following cmdlet

Unlock-ADAccount -Identity peter

 

PowerShell Cmdlet to Get & List AD Groups, Computers & OUs

If you want to get the complete list of the AD groups, run the following cmdlet

Get-ADGroup -Filter *

Therefore, if you want to get the list of members in any specific AD group like “IT-Helpdesk,” run the following cmdlet

Get-ADGroupMember -Identity "IT-Helpdesk"

getting list of group member cmdlet

Also, if you want to list all the computers joined in a domain, run the following cmdlet

Get-ADComputer -Filter *

However, if you need to remove any specific computer from AD, for Example, PC01, run the following cmdlet

This will remove the computer name PC01 from your Active Directory computers.

Remove-ADComputer -Identity "PC01"

Moreover, if you want to list the computer by operating system, run the following cmdlet

To find Windows 10 computers

Get-ADComputer -Filter {OperatingSystem -like "*Windows 10*"}

Listing Windows 11 computers

Get-ADComputer -Filter {OperatingSystem -like "*Windows 11*"}

Get Windows Server 2025, etc

Get-ADComputer -Filter {OperatingSystem -like "*Windows Server 2025*"}

Powershell cmdlet to get the os

Now, if you want to find all the OUs in your Active Directory, run the following cmdlet

Get-ADOrganizationalUnit -Filter *

 

PowerShell Cmdlets for Group Policy & DNS

To list all the group policies applied to your Active Directory, run the following cmdlet

Get-GPO -All

Therefore, if you want to export it to a CSV file, run the following cmdlet.

Get-GPO -All | Export-Csv -Path c:\reports\gpo.csv

Note: Make sure you have the reports folder already in the C:

PowerShell command csv gpo

Now, to get the list of DNS server zones, run the following cmdlet

Get-DnsServerZone

Furthermore, to add the DNS server resource A record, run the following cmdlet

This will create a Host A record by the name of App in our zone Techijack.local, pointing to IP 192.168.2.10

Add-DnsServerResourceRecordA -Name "App" -ZoneName "techijack.local" -Ipv4Address "192.168.2.10"

PowerShell adding host a record

Somehow, if you want to remove any Host A record from your DNS zone, you can run the following cmdlet.

This will remove the Host A record by the name of App from the DNS zone Techijack.local

Remove-DnsServerResourceRecord -ZoneName "techijack.local" -RRType "A" -Name "app"

 

Common PowerShell commands for Windows Services

To list all the services on the computer, run the following cmdlet

Get-Service

Therefore, if you want to stop any service, such as the spooler in our case, we run the following cmdlet

Stop-Service -Name "Spooler"

Once it is stopped, and you want to see the status of the same service, run the following cmdlet

Get-service -Name "spooler"

Now, it will show you as stopped

To start the same service, run the following cmdlet

Start-Service -Name "Spooler"

If you want to restart the service directly without stopping it, run the cmlet

Restart-Service -Name "Spooler"

 

PowerShell Commands to Get Eventlog, Test Net Connection

Event logs are a very important aspect, and you should check them from time to time.

So, to get the list newest 50 event logs, run the cmdlet

Get-EventLog -LogName System -Newest 50

Therefore, to check the internet connectivity along with port 443 opened or not, run the following cmdlet

Test-NetConnection -ComputerName google.com -port 443

This will show the connectivity test as successful if there is proper connectivity to the internet.

testing net connection with Common PowerShell Commands

 

Commands to Remotely Restart and Shutdown the Client PC in AD

You should know the name of the client PC you want to restart. To restart the client PC, run the following cmdlet

This will restart the client computer named PC01

Restart-Computer -ComputerName "PC01" -Force

Same way, if you want to shut down the computer, run the following cmdlet

This will shut down the client computer named PC01

Restart-Computer -ComputerName "PC01" -Force

 

Emailing PowerShell Result as an Attachment Report

Suppose you want to get an email alert for the daily user’s last logon reports.

You can set the PowerShell Script and schedule it, so that you can get the report every day for all users’ last logon.

You can run and schedule the script below to get the last logon report as an attachment.

$Date = Get-Date -Format "yyyy-MM-dd"
$ReportFile = "C:\Reports\DailyReport.csv"
# Export AD Users
$Users = Get-ADUser -Filter * -Property SamAccountName,
DisplayName, Enabled, LastLogonDate
$Users | Export-Csv $ReportFile -NoTypeInformation
# Send Email with Report Attachment
$sendMailMessageSplat = @{
    From = 'Administrator <administrator@techijack.net>'
    To = 'Jack <jack@techijack.net>'
    Subject = 'Daily User Report'
    Body = 'Pls find the attached user daily report'
    smtpServer = 'mail.techijack.net'
    Attachments = 'c:\reports\DailyReport.csv' 
}
Send-MailMessage @sendMailMessageSplat

Note: Make sure you set the proper path for the report and SMTP server according to your configuration

daily report sending attachment with powershell

 

Conclusion

Every system admin should be familiar with these common PowerShell commands to manage their systems in an Active Directory environment.

It is best practice to make a note of useful PowerShell commands in one place, so that they can be used when required.

By automating the PowerShell cmdlets and scheduling them.

Therefore, you can configure the daily email alerts that help manage your systems in your organization.

In case of any questions related to this article, feel free to contact.

I hope you will also like some more Active Directory Tutorials 

Moreover, if you want to see all the above PowerShell Commands in action, watch the video below

YouTube video

Vikas Jakhmola

Vikas Jakhmola, the founder of Techijack, with over 15+ years of experience in the IT industry.

Related Articles

Back to top button