List disk drives into an array

This Powershell script ist playing with an “athook” object based on an array having different named properties .

$Array = @()
Foreach ($vol In GET-WMIOBJECT win32_logicaldisk) 
 { 
 $obj = New-Object PSObject
 $Value = $vol.DeviceID
 $obj | Add-Member -MemberType NoteProperty -Name "Drive" -value $Value
 $Value =  $vol.Volumename
 $obj | Add-Member -MemberType NoteProperty -Name "Name" -value $Value
 $value = [math]::round(( $vol.Size/ 1073741824),0)
 $obj | Add-Member -MemberType NoteProperty -Name "SizeGB" -value $Value
 $value = [math]::round(( $vol.FreeSpace/ 1073741824),0)
 $obj | Add-Member -MemberType NoteProperty -Name "FreeGB" -value $Value
 $array += $obj
 }
$array  | out-gridview
This entry was posted in Information Technology and tagged . Bookmark the permalink.

Comments are closed.