PoshCode Logo PowerShell Code Repository

VM Disk Report by vinicius 36 months ago (modification of post by jgrote view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/5148"></script>download | new post

Gets all Virtual Machines, and exports a CSV that shows their virtual disk capacities and type. Used in this case for sizing a VCB temp disk.

  1. $VMs = get-vm
  2. $Results = @()
  3. foreach ($VM in $VMs) {
  4.     $Result = new-object PSObject
  5.     $Result | add-member -membertype NoteProperty -name "Name" -value $VM.Name
  6.     $Result | add-member -membertype NoteProperty -name "Description" -value $VM.Notes
  7.     $VMDiskCount = 1
  8.     get-harddisk $VM | foreach {
  9.         $disk = $_
  10.         $Result | add-member -name "Disk($VMDiskCount)SizeGB" -value ([math]::Round($disk.CapacityKB / 1MB)) -membertype NoteProperty
  11.         $Result | add-member -name "Disk($VMDiskCount)Type" -value $disk.DiskType -membertype NoteProperty
  12.         $VMDiskCount++
  13.     }
  14.     $Results += $Result
  15. }
  16. $Results | select-object * | export-csv -notypeinformation E:\VCBDiskReport.csv

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me