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 (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.