PowerShell for System Administrators

Practical PowerShell scripts and commands for Active Directory, Hyper-V, and daily admin tasks.

5 min read

Why PowerShell Matters

PowerShell isn't just a Windows shell -- it's a full automation platform that every Windows system administrator should master. With 15+ years in IT, I've seen the transition from batch files and VBScript to PowerShell, and the difference is night and day. PowerShell gives you programmatic access to everything: Active Directory, Hyper-V, file systems, the registry, WMI, and more.

If you're spending more than 5 minutes on a repetitive task, there's a PowerShell way to automate it. Period.

Getting Started with AD PowerShell

The ActiveDirectory module is installed by default on Domain Controllers. For remote management, install the RSAT tools on your workstation:

Install-WindowsFeature RSAT-AD-Tools

Essential AD commands every admin should know:

Hyper-V Automation

The Hyper-V PowerShell module lets you manage VMs programmatically. This is invaluable for homelab automation:

Combine these with scheduled tasks for automated VM maintenance. For example, stop all non-essential VMs at 10 PM and start them at 6 AM:

Get-VM | Where-Object {$_.Name -notlike "DC*" -and $_.Name -notlike "FS*"} | Stop-VM -TurnOff

File System and Disk Management

PowerShell makes file system operations fast and scriptable:

System Information and Monitoring

Useful Automation Scripts

Automated user offboarding:

Disable-ADAccount -Identity $username
Set-ADUser -Identity $username -AccountNotDelegated $true
Add-ADGroupMember -Identity "Password Reset Operators" -Members $username
Move-ADObject -Identity (Get-ADUser $username).DistinguishedName -TargetPath "OU=Disabled,DC=corp,DC=local"

Weekly stale account report:

Get-ADUser -Filter {Enabled -eq $true} -Properties LastLogonDate | Where-Object {$_.LastLogonDate -lt (Get-Date).AddDays(-60)} | Select-Object Name,LastLogonDate,EmailAddress | Export-Csv -Path "C:\Reports\StaleAccounts.csv"

VM health check:

Get-VM | Select-Object Name,State,CPUUsage,MemoryAssigned,Status | Format-Table

PowerShell Best Practices