Get WMI Disk Information


posted by jbruns2010
10-21-2010

Downloads: 833
File size: 1.1kB
Views: 5,881

Embed
Get WMI Disk Information
  1. Clear-Host 
  2. $strComputer = "." 
  3. $colDiskDrives = get-wmiobject -query "Select * From Win32_DiskDrive" -computer $strComputer 
  4. Foreach ($drive in $colDiskDrives
  5.     
  6.         Write-Host "Device ID: " $drive.DeviceID 
  7.         $a = $drive.DeviceID.Replace("\", "\\"
  8.         $colPartitions = get-wmiobject -query "Associators of {Win32_DiskDrive.DeviceID=""$a""} WHERE AssocClass = Win32_DiskDriveToDiskPartition" -computer $strComputer 
  9.        Foreach ($Partition in $colPartitions
  10.             
  11.                 $b = $Partition.DeviceID 
  12.                 $colLogicalDisk = get-wmiobject -query "Associators of {Win32_DiskPartition.DeviceID=""$b""} WHERE AssocClass = Win32_LogicalDiskToPartition" -computer $strComputer 
  13.                 If ($colLogicalDisk.Caption -ne $null
  14.                     
  15.                         Write-Host "Drive Letter: " $colLogicalDisk.Caption 
  16.                     
  17.                 Else 
  18.                     
  19.                         Write-Host "Drive Letter: NOT ASSIGNED" 
  20.                     
  21.                 Write-Host "Partition ID: " $Partition.DeviceID 
  22.                 $c = $colLogicalDisk.Size/1GB 
  23.                 $c = [math]::round($c, 2) 
  24.         Write-Host "Size: " $c"GB" 
  25.         Write-Host "Volume Name: " $colLogicalDisk.VolumeName 
  26.         Write-Host " " 
  27.             
  28.     

Use this to display disk information from a WMI point of view.

Copyright 2012 PowerShell.com. All rights reserved.