Hey Dev.to friends 👋
After doing some basic process logging in Windows using a Batch file (and then exploring Task Manager + Sysinternals), I decided it was time to level up a bit and try... PowerShell.
I’ll admit: at first, PowerShell felt like “Windows trying to be Linux.” But after writing my first sript? It started making sense. Sort of.
⚙️ What I Wanted to Build
A simple script that:
- Lists running processes
- Adds a timestamp
- Saves the info into a log file that I can revisit later
🧠 What I Wrote
$date = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
"--- $date ---" | Out-File -Append process_log.txt
Get-Process | Sort-Object CPU -Descending | Out-File -Append process_log.txt
"`n" | Out-File -Append process_log.txt
This logs all running processes sorted by CPU usage, with a timestamp, into a process_log.txt file. Prettiy clean, right?
🤔 What I Learned
PowerShell is actually kind of elegant once you get past the weird syntax
Out-File -Append is your best friend
Sorting and filtering are much easier than in Batch
Debugging PowerShell errors feels like reading Shakespeare sometimes 😅
🧪 Bonus Experiment
I left the script running with Task Scheduler every 10 minutes and then compared the logs manually.
I noticed some weird spikes in RuntimeBroker.exe and a random instance of wscript.exe I didn’t expect. Mighgt be nothing... or maybe the beginning of a rabbit hole 🐇
🎯 What’s Next
I want to:
Add filters (only show user-initiated processes)
Log changes only (diff between snapshots)
Maybe try sending logs via email for remote monitoring?
Still figuring things out, but this script was a big leap from the Batch stuff.
🙌 Final Thoughts
If you're new to PowerShell like I was, don’t stress — just build small stuff. Forget the theory at first, just write something dumb that does one thing. Then make it smarter later.
And if you know any cool tricks for process logging or filtering in PowerShell, I’d love to hear them!
Cheers,
Mohammad
Greate Blog, I love it