Combine `Get-Disk` info and `LogicalDisk` info in PowerShell? -


i have query scans logical disks information :

write-host "drive information $env:computername"  get-wmiobject -class win32_logicaldisk |     where-object {$_.drivetype -ne 5} |     sort-object -property name |      select-object name, volumename, volumeserialnumber,serialnumber, filesystem, description, volumedirty, `         @{"label"="disksize(gb)";"expression"={"{0:n}" -f ($_.size/1gb) -as [float]}}, `         @{"label"="freespace(gb)";"expression"={"{0:n}" -f ($_.freespace/1gb) -as [float]}}, `         @{"label"="%free";"expression"={"{0:n}" -f ($_.freespace/$_.size*100) -as [float]}} |     format-table -autosize 

the output is :

enter image description here

however - i'm after physical disks information , partitions / volume information :

so - physical disks have command :

get-disk

result :

enter image description here

question :

i want combine between 2 commands . want see disk , and below each disk - logical disk information :

  • disk number 1 : ....(info)
    >it's logical disks info.....
  • disk number 2 : ....(info)
    >it's logical disks info.....
  • disk number 3 : ....(info)
    >it's logical disks info.....
  • etc...

how can combine between 2 queries ?

you need query several wmi classes information want.

partitions can mapped disks using win32_diskdrivetodiskpartition class, , drives can mapped partitions via win32_logicaldisktopartition class.

get-wmiobject win32_diskdrive | % {   $disk = $_   $partitions = "associators of " +                 "{win32_diskdrive.deviceid='$($disk.deviceid)'} " +                 "where assocclass = win32_diskdrivetodiskpartition"   get-wmiobject -query $partitions | % {     $partition = $_     $drives = "associators of " +               "{win32_diskpartition.deviceid='$($partition.deviceid)'} " +               "where assocclass = win32_logicaldisktopartition"     get-wmiobject -query $drives | % {       new-object -type pscustomobject -property @{         disk        = $disk.deviceid         disksize    = $disk.size         diskmodel   = $disk.model         partition   = $partition.name         rawsize     = $partition.size         driveletter = $_.deviceid         volumename  = $_.volumename         size        = $_.size         freespace   = $_.freespace       }     }   } } 

Comments

Popular posts from this blog

php - isset function not working properly -

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -