This morning, I was browsing through Twitter, when I saw our teacher Brent Ozar (blog | twitter) give a tip about checking the disk usage , using the script of our friend and PowerSheller Aaron Nelson (blog | twitter)
You can view this nice script here –> Quick Blog: PowerShell Disk and MountPoint Check
And if I said you can be notified if the free space is below of , let´s say 90 MB, with a powershell command line?
I am with 80GB free space in my drive C:, so I put to be notified if it is below 90GB :
Remember that freemegabytes is in MB , so in my case 90000 MB.
and the output is
Ok ..This is so cool.
But surely you do not want this annoying message every 5 seconds.
Ha, How can I know it’s every 5 seconds?. Simple, the keyword WHITIN in WQL.
In the words of my good friend and PowerShell Jedi, Ravikanth Chaganti (blog | twitter), “WITHIN keyword is used to Specify the polling interval or the grouping interval specified number of seconds and is a floating point number.”
Well, if you STILL do not know what is WQL, I strongly suggest to download
But back to the subject, so just change to 3600 , to be reporting every hour.
As you probably know, there is a cmdlet in PowerShell 2.0 to send email (Send-MailMessage) , but I use Jakob Bindslet´s Send-SMTPmail (JBs Powershell) , but this is simply personal, because I like to use it.
So, with the Send-SMTPmail loaded into your User Profile, we can do :
and as you can see, works :
But Laerte, how do you know which property to use in WQL ?
Well, in Ravikanth´s EBook you will find a link to a WMI explorer (Set-Alias Pandora´s Box heheh ), a tool to facilitate our day
And if I search for Win32_PerfFormattedData_PerfDisk_LogicalDisk class, I will find all the properties that I can work :
(Yes, I drew it and yes, I did not have childhood)
Then this way, it is not so complicated. Now just change in WQL
targetinstance.<property> to the property that you want.
Well I’m tired and I have to do some remote work now..in the II part I will show how to make this code be scalable.
By By Guys..and BY BY ARGENTINA ……