Monitoring space is quite crucial in a critical system, or basically checking the disk space whether there is enough free space for continual operation is a good thing to consider in a production environment.
A simple PowerShell
script can save the day by monitoring the drive space of a specific drive that
needs to be checked or monitored.
It doesn’t
need a complex tool to do this kind of task.
Here’s a one-liner
PowerShell script to check free space on C drive.
Get-WmiObject Win32_LogicalDisk -filter "DeviceID
= 'c:' " | Select-Object {$_.FreeSpace
/1GB}
"DeviceID
= 'c:' " = this can be changed to any drive letter
Output of
the above command:
$_.FreeSpace /1GB
-----------------
293.042289733887
Or to
include the existing size of the drive, the command can be tweaked like this:
Get-WmiObject Win32_LogicalDisk -filter "DeviceID
= 'c:' " | Select-Object {$_.FreeSpace
/1GB} , {$_.size
/1GB}
Output:
$_.FreeSpace /1GB
$_.size /1GB
-----------------
------------
293.025550842285 1465.533344268799
Getting
the output is not enough, the script should have conditional statement, if a
certain threshold is cross then an alert or a notification send via email or
other methods should be sent for someone to take responsibility or action on what
to do next.
Check out this link using VBS to send email via o365:
https://quickbytesstuff.blogspot.com/2016/12/vbscript-send-email-via-office-365.html
Check out this link on how to set PowerShell script using Windows Task Scheduler:
https://quickbytesstuff.blogspot.com/2014/11/run-powershell-script-in-task-scheduler.html
Cheers...till next time. Stay safe and keep praying that this pandemic will end.
================================
Heaven's Dew Fall Prayer app for Android :
https://play.google.com/store/apps/details?id=com.myrosaryapp
Comments
Post a Comment