If you work in an MSP environment, you already know the truth:
๐ Repetitive tasks will slowly destroy your soul.
- Checking disk space
- Monitoring services
- Logging into multiple machines
- Fixing the same issues again and again
At some point, you realize:
โIโm not being paid to click the same thing 50 times.โ
Thatโs where PowerShell saves you.
Butโฆ
After a few โlearning experiencesโ (a.k.a. breaking things in production ๐ ), I realized:
๐ Automation is powerfulโฆ but dangerous.
So here are 5 PowerShell scripts every MSP should useโwritten in a safe, production-friendly way.
๐ ๏ธ 1. Disk Space Check (Prevent Tickets Before They Happen)
This is one of the most common MSP issues.
Instead of waiting for:
โMy computer is slowโ
You can detect problems early.
```powershell id="disk01"
$computers = @("PC1","PC2","PC3")
foreach ($computer in $computers) {
try {
$disks = Get-CimInstance Win32_LogicalDisk -ComputerName $computer -Filter "DriveType=3"
foreach ($disk in $disks) {
$freePercent = [math]::Round(($disk.FreeSpace / $disk.Size) * 100, 2)
if ($freePercent -lt 20) {
Write-Output "$computer - Low disk space on $($disk.DeviceID): $freePercent%"
}
}
}
catch {
Write-Output "Failed to check $computer"
}
}
๐ **Why this matters:**
You fix issues *before* users notice.
---
# ๐ 2. Safe Restart Script (No More Accidental Chaos)
Letโs be honestโฆ
๐ Weโve all restarted the wrong machine at least once.
Hereโs a safer version:
```powershell id="restart01"
$computers = @("PC1","PC2")
foreach ($computer in $computers) {
if (Test-Connection -ComputerName $computer -Count 1 -Quiet) {
Restart-Computer -ComputerName $computer -WhatIf
} else {
Write-Output "$computer is offline"
}
}
๐ Key feature: -WhatIf
This shows what would happen without actually doing it.
๐ง 3. Service Health Check (Catch Hidden Problems)
Some services fail silently.
This script helps you detect them quickly:
```powershell id="service01"
$services = @("Spooler","W32Time")
foreach ($service in $services) {
$status = Get-Service -Name $service
if ($status.Status -ne "Running") {
Write-Output "$service is NOT running"
}
}
๐ **Upgrade idea:** Automatically restart failed services (carefully!)
---
# ๐ 4. Local Admin Audit (Security Must-Have)
This is huge for cybersecurity.
You should always know:
๐ **Who has admin access?**
```powershell id="admin01"
$admins = Get-LocalGroupMember -Group "Administrators"
foreach ($admin in $admins) {
Write-Output $admin.Name
}
๐ Why this matters:
Unauthorized access = major security risk
๐ 5. Script Logging (The Thing Everyone Skips ๐ )
This is not optional.
Seriously.
```powershell id="log01"
Start-Transcript -Path "C:\Logs\msp_script.log"
Write-Output "Script started..."
Your script here
Write-Output "Script completed."
Stop-Transcript
๐ **Why this matters:**
* Debug faster
* Track actions
* Prove what happened
---
# โ ๏ธ The Most Important Rule
All these scripts are useful.
But the real difference is:
๐ **How you run them**
---
## ๐ง My Safety Checklist (Always Follow This)
Before running any script:
* Use `-WhatIf` whenever possible
* Test on ONE machine first
* Check permissions
* Add logging
* Assume something will fail
---
# ๐ Real Talk
PowerShell doesnโt make mistakes.
๐ **We do.**
PowerShell just executes our bad ideasโฆ very efficiently.
---
# ๐ Final Thought
If you use these scripts correctly:
* You save hours
* You reduce errors
* You look like a hero
If you use them incorrectly:
๐ You create a story for your next blog post ๐
---
# ๐ Your turn
* Whatโs your go-to PowerShell script?
* Ever automated something that wentโฆ very wrong?
Letโs share ๐
Top comments (0)