10 Best Windows PowerShell Commands for Windows Server Administrators

Windows PowerShell is a powerful scripting and automation tool that has become essential for Windows Server administrators. Unlike the traditional command prompt, PowerShell is built on .NET, allowing it to work seamlessly with complex administrative tasks.

By leveraging cmdlets (command-lets), administrators can streamline processes, automate repetitive tasks, and manage both local and remote systems efficiently. Here are the 10 best PowerShell commands every Windows Server administrator should know.

  1. Get-Service

The Get-Service cmdlet is used to retrieve the status of services running on a Windows Server. It’s especially useful for monitoring or troubleshooting services.

Examples:

Get-Service > Lists all services on the server.
Get-Service -Name wuauserv > Displays the status of the Windows Update service.
Get-Service | Where-Object {$_.Status -eq "Stopped"} > Lists all stopped services.

  1. Start-Service and Stop-Service

These cmdlets allow administrators to start and stop Windows services from the command line.

Examples:

Start-Service -Name wuauserv > Starts the Windows Update service.
Stop-Service -Name Spooler > Stops the Print Spooler service.
Stop-Service -Name Spooler -Force > Forces the service to stop, even if it doesn’t stop gracefully.

  1. Get-Process and Stop-Process

Get-Process provides detailed information about running processes, similar to tasklist in CMD, while Stop-Process allows you to terminate specific processes.

Examples:

Get-Process > Lists all currently running processes.
Get-Process -Name "notepad" > Lists all instances of Notepad.
Stop-Process -Name "notepad" > Terminates all instances of Notepad.
Stop-Process -Id 1234 > Terminates the process with the specific process ID (PID).

  1. Get-EventLog and Clear-EventLog

Windows Event Logs are critical for diagnosing issues on a Windows Server, and Get-EventLog retrieves entries from various event logs. You can also clear event logs using Clear-EventLog.

Examples:

Get-EventLog -LogName System -Newest 20 > Displays the 20 most recent events from the System log.
Get-EventLog -LogName Application -EntryType Error > Lists error events from the Application log.
Clear-EventLog -LogName Security > Clears the Security event log.

  1. Get-ADUser and Set-ADUser

For servers with Active Directory, Get-ADUser retrieves user information from the directory, while Set-ADUser modifies user properties.

Examples:

Get-ADUser -Identity username > Retrieves details about a specific user.
Get-ADUser -Filter * | Select-Object Name,LastLogonDate > Lists all users and their last logon date.
Set-ADUser -Identity username -PasswordNeverExpires $true > Configures a user’s password to never expire.

Note: Active Directory cmdlets require the Active Directory module, which can be installed through RSAT (Remote Server Administration Tools).

  1. Get-ADComputer

This cmdlet retrieves information about computers within Active Directory, useful for inventorying servers or client machines.

Examples:

Get-ADComputer -Filter * > Retrieves all computers in the domain.
Get-ADComputer -Identity "Server01" > Retrieves information for a specific computer.

  1. Invoke-Command

Invoke-Command allows you to run PowerShell commands on remote machines, making it an essential tool for managing remote servers.

Examples:

Invoke-Command -ComputerName Server01 -ScriptBlock {Get-Service} > Retrieves the list of services running on a remote server.
Invoke-Command -ComputerName Server01 -ScriptBlock {Restart-Service -Name wuauserv} > Restarts the Windows Update service on the remote server.

  1. Restart-Computer

The Restart-Computer cmdlet provides a way to restart a server locally or remotely.

Examples:

Restart-Computer > Restarts the local server.
Restart-Computer -ComputerName Server01 > Restarts a remote server.

You can also combine -Force to force a restart and -Wait to wait for the server to become available again.

  1. Test-Connection

This cmdlet functions similarly to the ping command but offers more flexibility and options. It’s used to test network connectivity.

Examples:

Test-Connection -ComputerName google.com > Tests connectivity to Google.
Test-Connection -ComputerName Server01 -Count 5 > Sends 5 ping requests to Server01.
Test-Connection -ComputerName Server01 -Quiet > Returns True if the connection is successful, False if it fails.

  1. Get-WindowsFeature and Install-WindowsFeature

These cmdlets are critical for managing roles and features on a Windows Server. Get-WindowsFeature lists the available or installed features, while Install-WindowsFeature installs new ones.

Examples:

Get-WindowsFeature > Lists all installed and available features.
Install-WindowsFeature -Name Web-Server > Installs the IIS web server role.
Install-WindowsFeature -Name AD-Domain-Services > Installs Active Directory Domain Services.

Conclusion

For Windows Server administrators, PowerShell provides a rich set of tools for automating tasks and managing systems. Mastering these commands allows you to efficiently monitor services, manage Active Directory, automate remote management, and troubleshoot issues across your environment. By incorporating PowerShell into your administrative toolkit, you can enhance your productivity and streamline server management operations.

If you've found this useful, you may want to sign up to our newsletter where you'll receive notices on when we post new articles and helpful "how tos". Just fill out your details below and we'll do the rest…

No Comments Yet.

Leave a comment


Sign up to our newsletter where you’ll receive notices on when we post new articles and helpful “how tos” to make your IT life easier.