Create Custom Monitors with PowerShell
Sometimes, as a developer, you want to be be able to keep track of free space on a drive, the size of a log, the load on your CPU, the number of users logged in, etc. With PowerShell, it is typically just a matter of finding the right cmdlet amidst the large (and rapidly growing) pool of cmdlets provided by Microsoft and by third parties. Then you just run Get-Foo to check details about the foo resource. And then you come back 5 minutes later and run it again because you want to see how it changes over time.
But wouldn’t it be nice if you could just have it run automatically at regular intervals in a separate window that you could just keep in the corner of your screen? Well, I found the barebones of just such a utility sometime ago (authored by Marc van Orsouw, aka ‘thePowerShellGuy’). His original post is no longer available, but I expanded upon his code and, over time, added features, bug fixes, and enhancements, making it more useful and more user-friendly. Here are a few screenshots of the Monitor Factory in action.
Monitor the size of a database
Start-Monitor -AsJob {Invoke-Sqlcmd ‘DBCC SQLPERF(logspace)’ |Select-Object 'Database Name','Log Size (MB)','Log Space Used (%)',HasErrors}
`
Monitor drives on a system
Monitor longest running DB queries
Build Your Own Resource Monitor in a Jiffy reveals how quick and easy it is to get started with the Monitor Factory.
Related Articles
Secure Your Powershell Session with JEA and Constrained Endpoints
Index What is a Constrained Endpoint and Why Would I Need One? Setup and Configuration Using our Endpoint What is a …
Read moreDo Anything in One Line of PowerShell
PowerShell provides a tremendous boon to productivity for computer professionals of all types. But, you have to admit: it can …
Read morePitfalls of the Pipeline
Pipelining is an important concept in PowerShell. Though the idea did not originate with PowerShell (you can find it used …
Read more