25 Essential PowerShell Commands for Sysadmins

A searchable reference of the PowerShell commands infrastructure and systems admins use most. Each command is listed with its category, what it does, and what it requires, followed by copy-ready examples.

Quick reference table

# Command Category What it does Module / requirement
1 Get-Command Discovery Finds commands by name, verb, noun, or module Built in
2 Get-Help Discovery Shows syntax, parameters, and examples for a command Built in; Update-Help (run as admin) downloads current help files
3 Get-Member Discovery Lists the properties and methods of an object Built in
4 Get-Service Services Lists services and their status Built in
5 Restart-Service Services Stops and starts a service Run as administrator
6 Get-Process Processes Lists running processes, including CPU time and memory Built in
7 Get-WinEvent Logging Queries Windows event logs, including filtering by ID and time Built in; reading the Security log requires elevation
8 Get-HotFix Patching Lists installed updates (KB numbers) May not list every installed update
9 Get-ComputerInfo System info Returns OS name, version, build, hardware, and BIOS details Windows PowerShell 5.1 and PowerShell 7 on Windows
10 Get-CimInstance System info Queries WMI/CIM classes such as OS, BIOS, and disks Built in on Windows
11 Get-Volume Storage Shows volumes, file system, size, and free space Storage module (Windows)
12 Get-NetIPConfiguration Networking Shows IP addresses, gateway, and DNS servers per adapter NetTCPIP module (Windows)
13 Test-NetConnection Networking Tests reachability and whether a TCP port is open Windows only
14 Resolve-DnsName Networking Queries DNS records (A, MX, TXT, and so on) DnsClient module (Windows)
15 Get-NetTCPConnection Networking Lists TCP connections and listening ports with owning process ID NetTCPIP module (Windows)
16 Get-NetFirewallRule Security Lists Windows Firewall rules and their settings NetSecurity module (Windows)
17 Get-ADUser Active Directory Retrieves user accounts and attributes RSAT ActiveDirectory module
18 Search-ADAccount Active Directory Finds locked, disabled, expired, or inactive accounts RSAT ActiveDirectory module
19 Get-ADGroupMember Active Directory Lists members of a group, optionally including nested groups RSAT ActiveDirectory module
20 Get-ChildItem Files and certificates Lists files, folders, registry keys, and certificate stores Built in
21 Get-FileHash Security Computes a file hash to verify integrity Built in; default algorithm is SHA256
22 Get-Acl Security Shows permissions on a file, folder, or registry key Built in
23 Invoke-Command Remoting Runs commands on one or many remote computers WinRM enabled (Enable-PSRemoting); default ports TCP 5985 (HTTP) and 5986 (HTTPS)
24 Export-Csv Reporting Writes objects to a CSV file In Windows PowerShell 5.1, add -NoTypeInformation to omit the #TYPE header; PowerShell 6+ omits it by default
25 Get-WindowsFeature Server roles Lists installed and available roles and features Windows Server only (ServerManager module)

Examples by category

Discovery

# Find commands containing "service"
Get-Command *service*

# Show examples for a command
Get-Help Get-Service -Examples

# See what properties a service object has
Get-Service | Get-Member

Services and processes

# Status of one service
Get-Service -Name Spooler

# Restart a service (run as administrator)
Restart-Service -Name Spooler

# Ten processes with the most accumulated CPU time
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10

The CPU property is total processor time in seconds since the process started, not current percentage usage.

Logs

# Failed logons (event ID 4625) in the last 24 hours
Get-WinEvent -FilterHashtable @{
    LogName   = 'Security'
    Id        = 4625
    StartTime = (Get-Date).AddHours(-24)
}

Using -FilterHashtable filters at the source, which is much faster than retrieving a log and filtering with Where-Object.

Patching and system information

# Ten most recently installed updates
Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 10

# OS name, version, and build number
Get-ComputerInfo -Property OsName, OsVersion, OsBuildNumber

# Last boot time
Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object LastBootUpTime

Storage

# Free and total space per volume
Get-Volume | Select-Object DriveLetter, FileSystemLabel, SizeRemaining, Size

Networking

# IP, gateway, and DNS per adapter
Get-NetIPConfiguration

# Check whether a server answers on TCP 443
Test-NetConnection -ComputerName server01 -Port 443

# MX records for a domain
Resolve-DnsName -Name example.com -Type MX

# Listening TCP ports sorted by port number
Get-NetTCPConnection -State Listen | Sort-Object LocalPort

In Test-NetConnection output, TcpTestSucceeded : True means the port accepted the connection.

Firewall

# Enabled inbound allow rules
Get-NetFirewallRule -Enabled True -Direction Inbound -Action Allow

Active Directory

# One user with logon-related attributes
Get-ADUser -Identity jdoe -Properties LastLogonDate, PasswordLastSet, Enabled

# Locked-out accounts
Search-ADAccount -LockedOut

# User accounts inactive for 90 days
Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly

# Everyone in Domain Admins, including nested group members
Get-ADGroupMember -Identity 'Domain Admins' -Recursive

LastLogonDate is derived from the lastLogonTimestamp attribute, which replicates between domain controllers on an interval and can lag behind real logons by up to about 14 days. Do not use it for exact last-logon times.

Files, certificates, and integrity

# Files not modified in 30 days
Get-ChildItem -Path C:\Logs -Recurse -File |
    Where-Object LastWriteTime -lt (Get-Date).AddDays(-30)

# Machine certificates expiring within 30 days
Get-ChildItem -Path Cert:\LocalMachine\My |
    Where-Object NotAfter -lt (Get-Date).AddDays(30)

# SHA256 hash of a file
Get-FileHash -Path .\installer.iso -Algorithm SHA256

# Permissions on a folder
Get-Acl -Path C:\Data | Format-List

Remoting and reporting

# Check the time service on several servers
Invoke-Command -ComputerName srv01, srv02 -ScriptBlock { Get-Service W32Time }

# Export services to CSV (Windows PowerShell 5.1)
Get-Service | Export-Csv -Path .\services.csv -NoTypeInformation

Server roles

# Installed roles and features on Windows Server
Get-WindowsFeature | Where-Object Installed

Notes on versions

  • Windows PowerShell 5.1 ships with Windows and uses the powershell.exe executable. PowerShell 7 is installed separately and uses pwsh.exe.
  • Most commands in the networking, storage, firewall, and Active Directory groups depend on Windows modules and are not available on Linux or macOS.
  • Active Directory cmdlets require the RSAT ActiveDirectory module on workstations. Domain controllers have it by default.

Sources

  • Microsoft Learn: PowerShell documentation (learn.microsoft.com/powershell)
  • Microsoft Learn: Active Directory module cmdlet reference
  • Microsoft Learn: NetTCPIP, NetSecurity, DnsClient, and Storage module references