🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

10 PowerShell One-Liners Every Windows Admin Needs in 2026

10 PowerShell One-Liners Every Windows Admin Needs in 2026

PowerShell one-liners are the Swiss army knife of Windows administration. These compact, powerful commands can replace hours of manual work with a single line of code. Whether you are managing a handful of servers or an enterprise fleet, these 10 one-liners will make your daily work faster and more reliable.

Each command below is tested on PowerShell 7.x and Windows Server 2022/2025. Copy them directly into your terminal or save them as snippets in your favorite editor.

1. Find the 10 Largest Files on a Drive

When disk space runs low, this one-liner quickly identifies the biggest offenders:

Get-ChildItem -Path C:\ -Recurse -File -ErrorAction SilentlyContinue | Sort-Object Length -Descending | Select-Object -First 10 FullName, @{N="SizeMB";E={[math]::Round($_.Length/1MB,2)}}

This recursively scans the C: drive, sorts files by size, and displays the top 10 with their paths and sizes in megabytes. The -ErrorAction SilentlyContinue flag suppresses permission errors for system directories you cannot access.

2. Check Disk Space on All Servers

Monitor disk utilization across multiple servers simultaneously:

Invoke-Command -ComputerName (Get-Content servers.txt) -ScriptBlock { Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" | Select-Object PSComputerName, DeviceID, @{N="FreeGB";E={[math]::Round($_.FreeSpace/1GB,2)}}, @{N="TotalGB";E={[math]::Round($_.Size/1GB,2)}}, @{N="PctFree";E={[math]::Round(($_.FreeSpace/$_.Size)*100,1)}} }

Create a servers.txt file with one server name per line, and this command pulls disk statistics from all of them in parallel.

3. Find All Locked-Out Active Directory Accounts

This is one of the most frequently used commands in any Active Directory environment:

Search-ADAccount -LockedOut | Select-Object Name, SamAccountName, LastLogonDate, LockedOut, PasswordExpired | Format-Table -AutoSize

Run this first thing every morning to proactively address account lockouts before users flood your help desk.

4. Get Uptime of Remote Servers

Quickly check how long your servers have been running:

Get-CimInstance -ComputerName Server01,Server02,Server03 -ClassName Win32_OperatingSystem | Select-Object CSName, @{N="Uptime";E={(Get-Date) - $_.LastBootUpTime}} | Format-Table -AutoSize

This is particularly useful after patch cycles to confirm which servers have been rebooted and which still need attention.

5. Export All AD Users to CSV

Generate a complete user report for auditing or HR review:

Get-ADUser -Filter * -Properties DisplayName, EmailAddress, Department, Title, LastLogonDate, Enabled, Created | Select-Object DisplayName, SamAccountName, EmailAddress, Department, Title, LastLogonDate, Enabled, Created | Export-Csv -Path "AD_Users_$(Get-Date -Format yyyyMMdd).csv" -NoTypeInformation

The filename automatically includes today's date, making it easy to maintain a historical record of user exports.

6. Kill All Processes by Name Across Remote Servers

When a runaway application needs to be stopped across your infrastructure:

Invoke-Command -ComputerName (Get-Content servers.txt) -ScriptBlock { Get-Process -Name "problematic-app" -ErrorAction SilentlyContinue | Stop-Process -Force; Write-Output "$env:COMPUTERNAME - Process stopped" }

Use this carefully in production environments and always verify the process name before executing.

7. Check Windows Update Status

See the last installed updates and pending updates on a system:

Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 15 HotFixID, Description, InstalledOn | Format-Table -AutoSize

This shows the 15 most recently installed patches, helping you verify that your update cycles are running on schedule.

8. Find Services Set to Auto-Start That Are Not Running

Identify services that should be running but have crashed or failed to start:

Get-CimInstance Win32_Service | Where-Object { $_.StartMode -eq "Auto" -and $_.State -ne "Running" -and $_.Name -notmatch "^(sppsvc|TrustedInstaller|wuauserv)" } | Select-Object Name, DisplayName, State, StartMode | Format-Table -AutoSize

The regex filter excludes commonly stopped auto-start services that are expected to be in that state.

9. Test Connectivity to Multiple Ports

Verify that critical services are accessible across your network:

@{Server1=@(80,443,3389);Server2=@(1433,80);Server3=@(22,443)}.GetEnumerator() | ForEach-Object { $server=$_.Key; $_.Value | ForEach-Object { $r=Test-NetConnection $server -Port $_ -WarningAction SilentlyContinue; [PSCustomObject]@{Server=$server;Port=$_;Open=$r.TcpTestSucceeded} } } | Format-Table -AutoSize

Customize the server names and ports in the hashtable at the beginning. This is perfect for post-deployment validation or network troubleshooting.

10. Generate a System Health Report

Create a quick system health snapshot combining CPU, memory, and disk information:

$cpu=Get-CimInstance Win32_Processor|Measure-Object LoadPercentage -Average; $mem=Get-CimInstance Win32_OperatingSystem; $disk=Get-CimInstance Win32_LogicalDisk -Filter "DeviceType=3"; [PSCustomObject]@{CPU="$([math]::Round($cpu.Average,1))%";RAM_Used="$([math]::Round(($mem.TotalVisibleMemorySize-$mem.FreePhysicalMemory)/1MB,1))GB";RAM_Total="$([math]::Round($mem.TotalVisibleMemorySize/1MB,1))GB";C_Free="$([math]::Round(($disk|Where-Object DeviceID -eq 'C:'|Select-Object -Expand FreeSpace)/1GB,1))GB"}

Run this on any server to get an instant picture of resource utilization. Pipe the output to a file or monitoring system for historical tracking.

Bonus: Create a PowerShell Profile for Quick Access

Save your favorite one-liners as functions in your PowerShell profile for instant access:

# Open your profile for editing
notepad $PROFILE

# Add functions like:
function Get-DiskReport { Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" | Select-Object DeviceID, @{N="FreeGB";E={[math]::Round($_.FreeSpace/1GB,2)}}, @{N="TotalGB";E={[math]::Round($_.Size/1GB,2)}} }
function Get-LockedUsers { Search-ADAccount -LockedOut | Select-Object Name, SamAccountName, LockedOut }

Recommended Reading

Level up your PowerShell skills with these Dargslan guides:

Share this article:

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.