Powershell Disk Space

If you found this useful, subscribe.

This is a newer, cleaner version of a previous post.



# Getting disk information
[System.Object[]]$disks = @()
$Private:wmiDisks = (Get-WmiObject Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3})

foreach ($Private:wmiDisk in $wmiDisks){
$Private:tmp = New-Object -TypeName System.Object
$tmp | Add-Member -Name DeviceID -Value $wmiDisk.DeviceID -MemberType NoteProperty
$tmp | Add-Member -Name FreeSpace -Value $([Math]::Truncate($wmiDisk.FreeSpace / 1GB)) -MemberType NoteProperty
$tmp | Add-Member -Name TotalSpace -Value $([Math]::Truncate($wmiDisk.Size / 1GB)) -MemberType NoteProperty
$disks += $tmp}

I also have made a monitoring system free for your use, here.



One thought on “Powershell Disk Space

Comments are closed.