Beginner
PowerShell Scripting Basics for Sysadmins
Variables, loops and functions — the essential building blocks to automate Windows admin tasks.
Admin 10 October 2026 6 min read 2 views
PowerShell scripting basics
PowerShell lets you automate repetitive admin tasks. Here are the building blocks.
Variables and output
$name = "Server01"
Write-Host "Checking $name..."
Loops
1..5 | ForEach-Object { Write-Host "Ping attempt $_" }
A simple function
function Get-DiskFree {
Get-PSDrive -PSProvider FileSystem |
Select-Object Name, @{N='FreeGB';E={[math]::Round($_.Free/1GB,1)}}
}
Get-DiskFree
Pro Tip: Save scripts with a
.ps1extension and run them with./script.ps1.
#powershell#scripting#automation
Back to all guides