PowerShell Commands for IT Support

Copy-ready PowerShell commands for networking, Active Directory, Exchange Online, Windows and more. Curated by Zenith Services Inc. (ZSI).

69 commands shown

How to use these PowerShell commands

These are PowerShell commands our team uses for everyday troubleshooting and administration. Search or pick a category, press Copy, then replace anything in <angle brackets> with your own value. Green means read-only, and orange means the command makes changes.

Looking for downloads and sign-in pages? See our IT tools and support links.

Networking commands

Read-only

Show full IP configuration

See IP address, gateway, DNS servers and DHCP details for every adapter.

ipconfig /all
Makes changes

Flush the DNS cache

Clear cached DNS answers after a DNS or web filter change.

ipconfig /flushdns
Makes changes

Renew a DHCP address

Release and request a new IP address from DHCP.

ipconfig /release
ipconfig /renew
Read-only

Look up a host name

Check which DNS server answers and what address it returns.

nslookup <host.example.com>
Read-only

Look up a host against a chosen DNS server

Compare your internal DNS answer with a public resolver.

nslookup <host.example.com> 1.1.1.1
Read-only

Test a TCP port

Check whether a remote host accepts connections on a port, such as 3389 for RDP.

Test-NetConnection <HostName> -Port <Port>
Read-only

Trace the route to a host

See each network hop on the way to an address.

tracert 8.8.8.8
Read-only

List network adapters

Show adapter status, link speed and driver version.

Get-NetAdapter | Format-Table Name,InterfaceDescription,Status,LinkSpeed,DriverVersion -AutoSize
Read-only

Check adapter power saving

Find adapters that Windows may turn off to save power. Some adapters do not support this and show an error.

Get-NetAdapterPowerManagement | Format-Table Name,AllowComputerToTurnOffDevice,SelectiveSuspend,DeviceSleepOnDisconnect -AutoSize
Read-only

Show Wi-Fi connection details

See the band, channel, signal and receive rate of the current Wi-Fi connection.

netsh wlan show interfaces
Read-only

Find what is using a port

Show the process listening on a local TCP port.

Get-NetTCPConnection -LocalPort <Port> -State Listen | ForEach-Object { Get-Process -Id $_.OwningProcess }

Active Directory commands

Read-only

Find the domain controller

Confirm the PC can find a domain controller for the domain.

nltest /dsgetdc:<ad.example.com>
Read-only

Show a user sign-in name

Check a user account name and UPN.

Get-ADUser <UserName> | Select-Object SamAccountName,UserPrincipalName
Read-only

Count all AD users

Get a quick total of user accounts in the domain.

Get-ADUser -Filter * | Measure-Object
Makes changes

Change a user UPN

Set the sign-in name, for example to match Microsoft 365.

Set-ADUser <UserName> -UserPrincipalName <UserName>@<example.com>
Read-only

List a user group memberships

See the groups a user belongs to.

(Get-ADPrincipalGroupMembership <UserName>).Name
Makes changes

Copy groups from one user to another

Give a new user the same groups as an existing user.

(Get-ADUser <ExistingUser> -Properties MemberOf).MemberOf | ForEach-Object { Add-ADGroupMember -Identity $_ -Members <NewUser> }
Read-only

List all computers in AD

Show the name of every computer account.

Get-ADComputer -Filter * | Select-Object Name
Read-only

Check if a computer account is enabled

Confirm a computer account has not been disabled.

(Get-ADComputer <ComputerName>).Enabled
Makes changes

Join a PC to a domain and rename it

Join the domain, set a new name and restart. It asks for domain admin credentials.

Add-Computer -DomainName <ad.example.com> -NewName <NewComputerName> -Credential (Get-Credential) -Restart
Makes changes

Rename a computer

Rename this PC and restart it.

Rename-Computer -NewName <NewComputerName> -Restart
Makes changes

Refresh Group Policy

Apply the latest Group Policy settings now.

gpupdate /force
Read-only

See which GPOs applied

List the computer policies that reached this PC.

gpresult /r /scope computer
Read-only

Check the time source

Kerberos sign-in can fail when clocks differ by more than 5 minutes.

w32tm /query /source
w32tm /query /status

Microsoft 365 and Entra commands

Read-only

Check the signed-in UPN

Show the sign-in name Windows is using.

whoami /upn
Read-only

Check device join state

See whether a PC is joined to Entra ID, workplace joined or domain joined.

dsregcmd /status | Select-String 'AzureAdJoined|WorkplaceJoined|DomainJoined|TenantName'
Makes changes

Install the Graph module

Install the Microsoft Graph sign-in module for your account.

Install-Module Microsoft.Graph.Authentication -Scope CurrentUser
Read-only

Connect to Microsoft Graph

Sign in to Graph with the permissions you need.

Connect-MgGraph -Scopes 'User.Read.All' -NoWelcome
Read-only

Check the Graph session

See which account and permissions the session is using.

Get-MgContext

Exchange Online commands

Makes changes

Install the Exchange Online module

Install the module for your account.

Install-Module ExchangeOnlineManagement -Scope CurrentUser
Read-only

Connect to Exchange Online

Sign in with an admin account.

Connect-ExchangeOnline -UserPrincipalName <admin@example.com> -ShowBanner:$false
Read-only

Export all mailboxes to CSV

Save mailbox type and forwarding settings to a file.

Get-EXOMailbox -ResultSize Unlimited -Properties RecipientTypeDetails,ForwardingAddress,ForwardingSmtpAddress | Select-Object DisplayName,PrimarySmtpAddress,RecipientTypeDetails,ForwardingAddress,ForwardingSmtpAddress | Export-Csv .\Mailboxes.csv -NoTypeInformation
Read-only

Check mailbox size

See item count and total size for one mailbox.

Get-MailboxStatistics -Identity <user@example.com> | Select-Object DisplayName,ItemCount,TotalItemSize
Read-only

Check mailbox forwarding

See whether a mailbox forwards email elsewhere.

Get-Mailbox <user@example.com> | Format-List RecipientTypeDetails,ForwardingAddress,ForwardingSmtpAddress,DeliverToMailboxAndForward
Read-only

Find inbox rules that forward email

Useful when you suspect a compromised mailbox.

Get-InboxRule -Mailbox <user@example.com> | Where-Object { $_.ForwardTo -or $_.ForwardAsAttachmentTo -or $_.RedirectTo } | Select-Object Name,Enabled,ForwardTo,RedirectTo
Read-only

List who can access a mailbox

Show delegates, without the built-in system accounts.

Get-MailboxPermission <user@example.com> | Where-Object { $_.User -notlike 'NT AUTHORITY*' } | Format-Table User,AccessRights
Makes changes

Give full access to a mailbox

Let a user open a shared or delegated mailbox.

Add-MailboxPermission -Identity <shared@example.com> -User <user@example.com> -AccessRights FullAccess -InheritanceType All
Makes changes

Give Send As permission

Let a user send email as a shared mailbox.

Add-RecipientPermission -Identity <shared@example.com> -Trustee <user@example.com> -AccessRights SendAs -Confirm:$false
Read-only

List distribution group members

Show the members of one distribution group.

Get-DistributionGroupMember -Identity <group@example.com> -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress
Read-only

List Microsoft 365 group members

Show the members of one Microsoft 365 group.

Get-UnifiedGroupLinks -Identity <group@example.com> -LinkType Members -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress
Read-only

Find inactive and deleted mailboxes

List mailboxes that can still be recovered.

Get-Mailbox -InactiveMailboxOnly -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress
Get-Mailbox -SoftDeletedMailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress
Read-only

Review mail flow rules

List transport rules, their state and priority.

Get-TransportRule | Select-Object Name,State,Priority,Mode
Read-only

Review accepted domains

List the email domains the tenant accepts.

Get-AcceptedDomain | Select-Object DomainName,DomainType,Default
Read-only

Check mailbox protocols

See which mailboxes allow POP, IMAP and ActiveSync.

Get-EXOCASMailbox -ResultSize Unlimited -Properties PopEnabled,ImapEnabled,ActiveSyncEnabled | Select-Object PrimarySmtpAddress,PopEnabled,ImapEnabled,ActiveSyncEnabled

Windows system info commands

Read-only

Show PC and Windows details

See the computer name, Windows edition and build.

Get-ComputerInfo | Select-Object CsName,OsName,OsVersion,OsBuildNumber
Read-only

List user profiles on a PC

See profiles and last use before moving data or replacing a PC.

Get-CimInstance Win32_UserProfile | Where-Object { -not $_.Special } | Select-Object LocalPath,Loaded,LastUseTime
Read-only

List disk volumes

See size and free space on local drives.

Get-CimInstance Win32_Volume -Filter 'DriveType=3' | Select-Object Name,Label,@{n='SizeGB';e={[int]($_.Capacity/1GB)}},@{n='FreeGB';e={[int]($_.FreeSpace/1GB)}}
Read-only

List installed updates

Show the latest Windows updates, newest first.

Get-CimInstance Win32_QuickFixEngineering | Sort-Object InstalledOn -Descending | Select-Object -First 15 HotFixID,Description,InstalledOn
Read-only

Check page file use

See page file size and peak use.

Get-CimInstance Win32_PageFileUsage | Select-Object Name,AllocatedBaseSize,CurrentUsage,PeakUsage
Read-only

Check BitLocker status

See encryption status for each drive.

Get-BitLockerVolume -ErrorAction SilentlyContinue | Select-Object MountPoint,VolumeStatus,ProtectionStatus,EncryptionPercentage
Read-only

List devices by class

See the status of connected devices, such as keyboards.

Get-PnpDevice -Class Keyboard -PresentOnly | Select-Object Status,FriendlyName,InstanceId
Read-only

Find a printer

Check whether a printer is installed and its port.

Get-CimInstance Win32_Printer | Select-Object Name,PortName,Default,PrinterStatus
Read-only

Check sleep and lid settings

View the current power plan settings.

powercfg /q SCHEME_CURRENT SUB_SLEEP STANDBYIDLE
powercfg /q SCHEME_CURRENT SUB_BUTTONS LIDACTION
Read-only

List SQL Server services

See SQL services and their state.

Get-CimInstance Win32_Service | Where-Object { $_.Name -match '^(MSSQL|SQLAgent|SQLSERVERAGENT|SQLBrowser|ReportServer)' } | Select-Object Name,State,StartMode,StartName

Event logs commands

Read-only

Find unexpected restarts

Look for crash, shutdown and restart events in the last 7 days.

Get-WinEvent -FilterHashtable @{LogName='System'; Id=41,1074,6008; StartTime=(Get-Date).AddDays(-7)} | Format-Table TimeCreated,Id,Message -Wrap
Read-only

Show recent application errors

List errors from the Application log in the last 6 hours.

Get-WinEvent -FilterHashtable @{LogName='Application'; Level=2; StartTime=(Get-Date).AddHours(-6)} -ErrorAction SilentlyContinue | Format-Table TimeCreated,ProviderName,Id -AutoSize
Read-only

Check Hyper-V switch events

Read recent events from the virtual switch log.

Get-WinEvent -LogName 'Microsoft-Windows-Hyper-V-VmSwitch-Operational' -MaxEvents 40 -ErrorAction SilentlyContinue | Format-Table TimeCreated,Id,Message -Wrap

Hyper-V and VMware commands

Read-only

Check a virtual machine

See whether a VM is running.

Get-VM <VMName>
Read-only

Check a VM network adapter

See the virtual switch, status and IP addresses of a VM.

Get-VMNetworkAdapter -VMName <VMName> | Format-Table SwitchName,Status,IPAddresses -AutoSize
Read-only

List virtual switches

See each switch, its type and physical adapter.

Get-VMSwitch | Format-Table Name,SwitchType,NetAdapterInterfaceDescription -AutoSize
Makes changes

Install VMware PowerCLI

Install the VMware management module for your account.

Install-Module VMware.PowerCLI -Scope CurrentUser

Security checks commands

Read-only

Check whether LLMNR is off

A value of 0 means LLMNR is turned off by policy. No result means no policy is set.

Get-ItemProperty 'HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\DNSClient' -Name EnableMulticast -ErrorAction SilentlyContinue | Select-Object EnableMulticast
Read-only

Check whether mDNS is off

A value of 0 means mDNS is turned off. No result means no setting has been made.

Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters' -Name EnableMDNS -ErrorAction SilentlyContinue | Select-Object EnableMDNS
Read-only

Check NetBIOS on adapters

A TcpipNetbiosOptions value of 2 means NetBIOS is turned off on that adapter.

Get-CimInstance Win32_NetworkAdapterConfiguration -Filter 'IPEnabled = True' | Select-Object Description,TcpipNetbiosOptions

Files and scripts commands

Makes changes

Copy a user profile with Robocopy

Copy documents and settings, skipping AppData, and write a log. Check the source and destination before running.

robocopy "C:\Users\<UserName>" "<D:\Backup\UserName>" /E /COPY:DAT /R:1 /W:1 /XJ /XD AppData /LOG:"<D:\Backup\UserName.log>"
Makes changes

Allow a script for this session only

Let scripts run in this window. The setting ends when the window closes.

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
Makes changes

Unblock a downloaded script

Remove the internet download flag from a script you trust.

Unblock-File -Path <.\Script.ps1>
Makes changes

Close stuck background Office apps

Stop Excel processes with no open window. Save your work first.

Get-Process EXCEL -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowTitle -eq '' } | Stop-Process -Force
Makes changes

Update an app with winget

Update one installed app by its package ID.

winget upgrade <Publisher.AppName>

Test commands on one system first, use them only on systems you are authorised to manage, and read what a command does before running it. Some commands need an elevated PowerShell window or the matching module. These commands are provided as a guide, without warranty.

PowerShell commands: frequently asked questions

What are PowerShell commands used for?

PowerShell commands let IT teams check and manage Windows, networks, Active Directory and Microsoft 365 from a command line. They are useful when you need a quick answer or want to repeat the same step on many systems.

Do I need to run PowerShell as an administrator?

Many read-only commands work in a normal window. Commands that change settings often need an elevated window, and some need a module such as ExchangeOnlineManagement or the Active Directory tools.

What does the text in angle brackets mean?

Text such as <UserName> is a placeholder. Replace it, including the brackets, with your own value before you run the command.

Are these commands safe to run?

Commands marked read-only only view information. Commands marked as making changes can affect your system, so test them first and use them only on systems you are authorised to manage.

Need help beyond these PowerShell commands?

Contact ZSI at support@zenservices.tech or +592-735-5555, or see our managed IT services.