Windows Servers
Managing Windows Server with PowerShell: A Practical Admin Guide
By NileVPS Team · Published · 4 min read
اقرأ المقال بالعربيGraphical tools such as Server Manager are fine for an occasional change, but once you manage more than one server, or repeat the same task every week, PowerShell becomes the faster and more reliable option. Every role and setting in Windows Server can be inspected and changed from the shell, and the same commands work over a remote session or inside a scheduled script. This guide walks through the commands an administrator uses daily on a Windows VPS, grouped by task, so you can copy them, adapt them and build your own routines.
Windows PowerShell 5.1 or PowerShell 7?
Windows Server 2016, 2019 and 2022 ship with Windows PowerShell 5.1 (powershell.exe). It contains every server module: ServerManager, NetTCPIP, NetSecurity, Storage, ActiveDirectory and so on. PowerShell 7 (pwsh.exe) is a separate, cross-platform install that runs side by side. It is faster and has newer language features, and most Windows modules load in it, but a few older ones still work best in 5.1. A sensible approach is to keep 5.1 for role management and use 7 for your own scripts if you like.
Check the version you are running:
$PSVersionTable.PSVersionFinding your way around
Three commands answer most "how do I…" questions without leaving the shell:
Get-Command -Noun *Firewall* # find commands by noun
Get-Help New-NetFirewallRule -Examples
Get-Service | Get-Member # see properties and methods of the outputRun Update-Help once (as administrator, with internet access) to download full help files.
Everyday server tasks
Services and processes
Get-Service | Where-Object Status -eq 'Running'
Restart-Service -Name Spooler
Set-Service -Name Spooler -StartupType Disabled
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
Stop-Process -Name notepad -ForceRoles and features
Get-WindowsFeature | Where-Object Installed
Install-WindowsFeature -Name Web-Server -IncludeManagementTools
Uninstall-WindowsFeature -Name Web-ServerAdd -WhatIf to see what would happen before you commit, and check the RestartNeeded column in the output.
Networking
Get-NetIPAddress -AddressFamily IPv4
Get-NetIPConfiguration
Get-DnsClientServerAddress
Test-NetConnection example.com -Port 443
Resolve-DnsName example.comTest-NetConnection replaces the old habit of using telnet to check whether a port is reachable.
Windows Firewall
New-NetFirewallRule -DisplayName "Allow HTTPS" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
Get-NetFirewallRule -Enabled True -Direction Inbound | Select-Object DisplayName, Profile
Remove-NetFirewallRule -DisplayName "Allow HTTPS"Remember that the Windows Firewall works inside the server. On NileVPS you can also filter traffic before it reaches the VPS with the cloud firewall, which is the right place to restrict RDP (3389) to your own IP addresses.
Users and local groups
$pw = Read-Host -AsSecureString "Password"
New-LocalUser -Name "deploy" -Password $pw -PasswordNeverExpires
Add-LocalGroupMember -Group "Remote Desktop Users" -Member "deploy"
Get-LocalGroupMember -Group "Administrators"Disks and storage
Get-Disk
Get-Volume
Get-PSDrive -PSProvider FileSystemEvent logs
Get-WinEvent -LogName System -MaxEvents 20
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625; StartTime=(Get-Date).AddHours(-24)}Event ID 4625 is a failed logon, a quick way to see whether someone is guessing passwords against your RDP port. Our guide to Event Viewer logs explains the most useful IDs.
Updates and system information
Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 5
Get-ComputerInfo -Property OsName, OsVersion, CsTotalPhysicalMemory
Rename-Computer -NewName "web01" -RestartOn Server Core, or when you want a menu, sconfig handles updates, networking and remote management interactively.
Remote management
PowerShell remoting (WinRM) lets you run commands on another server without opening an RDP session. It is enabled by default on Windows Server for domain networks.
Enable-PSRemoting -Force
Enter-PSSession -ComputerName web01
Invoke-Command -ComputerName web01, web02 -ScriptBlock { Get-Service W3SVC }Outside a domain, remoting needs extra setup: HTTPS listeners on port 5986 or adding the target to TrustedHosts. Never expose WinRM ports (5985/5986) to the whole internet; allow them only from known addresses or over a VPN.
From commands to scripts
Save repeated work in a .ps1 file. A small health check might look like this:
$report = [PSCustomObject]@{
Time = Get-Date
FreeC_GB = [math]::Round((Get-Volume -DriveLetter C).SizeRemaining / 1GB, 1)
Stopped = (Get-Service | Where-Object { $_.StartType -eq 'Automatic' -and $_.Status -ne 'Running' }).Name -join ', '
}
$report | Export-Csv C:\Reports\health.csv -Append -NoTypeInformationSchedule it with Task Scheduler:
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -File C:\Scripts\health.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At 7am
Register-ScheduledTask -TaskName "DailyHealth" -Action $action -Trigger $trigger -User "SYSTEM"The default execution policy on Windows Server is RemoteSigned, so local scripts run, while downloaded scripts must be signed or unblocked with Unblock-File after you have reviewed them.
Good habits checklist
| Habit | Why it matters |
|---|---|
Use -WhatIf and -Confirm | Preview destructive changes |
Log with Start-Transcript | Keeps a record of what you ran |
| Prefer full cmdlet names in scripts | Aliases like % and ? hurt readability |
| Take a snapshot before big changes | Fast rollback if something breaks |
| Store scripts in Git | History and review of changes |
If you need a server to practise on, you can deploy a Windows VPS in a few minutes and test every command here without risk to production.
FAQ
Do I need to install anything to use PowerShell on Windows Server?
No. Windows PowerShell 5.1 and the server management modules are built in. PowerShell 7 is optional and installed separately if you want its newer features.
Can PowerShell replace Remote Desktop entirely?
For most administration, yes. Remoting, Windows Admin Center and sconfig cover services, roles, updates and logs. You may still want RDP for graphical applications that have no command-line interface.
Is it safe to run scripts found online?
Only after reading them line by line. Scripts run with your permissions, so an unreviewed script can change or delete anything you can. Test on a snapshot or a spare VPS first.