# VARIABLES $outputFile = 'D:\scripts\VMDiskOverview.csv' # Output file path $VCServer = "MyVCServer" # Virtual Center Server # SCRIPT $VC = Connect-VIServer $VCServer # Connect to Virtual Center $myCol = @() # Prepare output collection $VMs = Get-VM | Sort Name # Get all VMs (sorted) $counter = 0 # Initialize counter for progress bar ForEach ($VM in $VMs) # Loop through VMs { $counter++ # Increase counter for progress bar Write-Progress -Activity "Gathering disk information" -Status "Processing VM $VM" -PercentComplete (100*($counter/$VMs.count)) # Display progress bar $VMHost = Get-VMHost -VM $VM # Get this VM's host $VMHostView = $VMHost | Get-View # Get advanced properties of host ForEach ($DISK in $VM.HardDisks) # Loop through VM's harddisks { $myObj = "" | Select VM, Description, Disk, Datastore, hexLUN0, hexLUN1, hexLUN2, hexLUN3, SAN # Create output object $myObj.VM = $VM.Name # Virtual Machine Name $myObj.Description = $VM.Description # Virtual Machine Description $myObj.Disk = $DISK.Name # Virtual Disk Name $myObj.Datastore = $DISK.Filename.Split("[]")[1] # Datastore Name $extents = ($VMHostView.Config.FileSystemVolume.MountInfo | Where {$_.Volume.Name -eq $myObj.Datastore}).Volume.Extent # Extents for this datastore If ($extents.GetType().BaseType -match "Array") # In case of multiple extents { For ($i = 0; $i -lt $extents.count; $i++) # Increment a counter { $myObj."hexLUN$i" = "{0:X}" -f [int]$extents[$i].DiskName.Split(":")[2] # LUN ID converted to HEX Write-Progress -Activity "Gathering disk information" -Status ("Processing VM $VM - Found LUN {0}" -f $myObj."hexLUN$i") -PercentComplete (100*($counter/$VMs.count)) # Disply progress bar } } Else # In case of single extent { $myObj.hexLUN0 = "{0:X}" -f [int]$extents.DiskName.Split(":")[2] # LUN ID converted to HEX Write-Progress -Activity "Gathering disk information" -Status ("Processing VM $VM - Found LUN {0}" -f $myObj.hexLUN0) -PercentComplete (100*($counter/$VMs.count)) # Display progress bar } $myObj.SAN = ($VMHostView.Config.StorageDevice.SCSILUN | Where {$_.CanonicalName -eq $extents[0].DiskName}).Vendor # SAN Vendor Clear-Variable Extents -ErrorAction SilentlyContinue # Cleanup variable(s) $myCol += $myObj # Add output to collection } } $myCol | Export-Csv $outputFile -NoTypeInformation # Export output to csv Invoke-Item $outputFile # Launch outout file