Managing drives, monitoring space to ensure that a drive run out of available capacity and to understanding just how many drives are on a single system this are simply able to monitor using PowerShell instead of manual monitoring.ย WMI – Windows Management Instrumentation can be a wealth of information that anyone should be able to query to get pretty much whateverย information they need.
1 2 |
#Look at only local drives Get-WmiObject -Class Win32_logicaldisk -Filter "DriveType = '3'" |
1 2 3 4 5 6 |
DeviceID : C: DriveType : 3 ProviderName : FreeSpace : 35938738176 Size : 127509983232 VolumeName : OSDisk |
In this post, we going to discuss about very simple query to get the Drive information. You can run the below query using the Get-WMIObject cmdlet to get more information about all of the drives on your system. From the above output, you can able to see that we have the DeviceID, which is the drive letter assigned to the drive; the FreeSpace, which is measured in bytes, as well as the capacity (size) of the drive;ย along with the volume name that has been specified.
Using the above information you can able to easily filter using the query for only drives that matched a certain type and while viewing the size in bytes is necessary to keep the size at the lowest possible level, sometimes it is nice to see it in a moreย readable format, such as in GB like below, The property is specified by a hash table with two keys, Label and Expression.The name of the property is assigned to the Label key. The calculation is assigned to the Expression key.
1 2 3 4 |
Get-WmiObject -Class Win32_logicaldisk -Filter "DriveType = '3'" | Select-Object -Property DeviceID, DriveType, VolumeName, @{Label='FreeSpaceGB';E={"{0:N2}" -f ($_.FreeSpace /1GB)}}, @{Label="Capacity";E={"{0:N2}" -f ($_.Size/1GB)}} |
OUTPUT:
Leave A Comment