PowerCli getVMDiskInfo

Tobias Automation, Scripts, vSphere Leave a Comment

Einführung

Für den Fall das man genaue Infos zu seinen vDisks und vor allem seinen RAW Disks haben möchte, hier ein PowerCLI Skript was helfen kann.

Ausgabe

In dieser Version werden die Daten in ein Excel Datei geschrieben.

Requirements

getestet mit PowerCLI 6 und installiertem Microsoft Excel 2013 oder höher

Script

 

<# .SYNOPSIS Export Disk Parameter from VMs to Excel .DESCRIPTION Export Disk Parameter from VMs to Excel. Detailed Infos for RAW Disks. You can call the script for all VMs in a VCenter or specific cluster or vm .Requirements Tested with PowerCLI 6 Installed Microsoft Excel .EXAMPLE &(„getVMDiskInfo.ps1“ -VCenter "yourVCenter" -Cluster "yourCluster") &(„getVMDiskInfo.ps1“ -VCenter "yourVCenter" -VM "yourVM") &(„getVMDiskInfo.ps1“ -VCenter "yourVCenter") .NOTES Author: Tobias Feuling – [email protected] #> Param( [Parameter(Mandatory=$True)] [string]$VCenter, [Parameter(Mandatory=$False)] [string]$Cluster, [Parameter(Mandatory=$False)] [string]$VM ) if(-not (Get-Module VMware.VimAutomation.Core)) { Import-Module VMware.VimAutomation.Core } $server = Connect-VIServer $VCenter if ($cluster -ne ""){ $clustervm = get-cluster $Cluster -server $server if ($VM -eq ""){ $VMS = $clustervm | get-vm } else { $VMS = $clustervm | get-vm -name $VM } } else { if ($VM -eq ""){ $VMS = get-vm -server $server } else { $VMS = get-vm -server $server -name $VM } } $objExcel = New-Object -ComObject Excel.Application $objExcel.Visible = $true $workbook = $objexcel.Workbooks.Add() $sheet = $Workbook.WorkSheets.item(1) $row = 1 $Sheet.Cells.Item($row,1) = "VM Name" $Sheet.Cells.Item($row,2) = "LUN Name" $Sheet.Cells.Item($row,3) = "Size" $Sheet.Cells.Item($row,4) = "Device Name" $Sheet.Cells.Item($row,5) = "VMDK Name" $Sheet.Cells.Item($row,6) = "Disk Name" $Sheet.Cells.Item($row,7) = "SCSI ID" $Sheet.Cells.Item($row,8) = "SCSI Controller" $Sheet.Cells.Item($row,9) = "LUN ID" $row++ foreach ($VMobj in $VMS) { $VMView = $VMobj | get-view foreach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "SCSI Controller"})) { foreach ($VirtualDiskDevice in ($VMView.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key})) { $Sheet.Cells.Item($row,1) = $VMobj.name if ($VirtualDiskDevice.Backing.CompatibilityMode -eq "physicalMode"){ $CononicalName = $VMobj | get-HardDisk | Where-Object {$_.DeviceName -eq $VirtualDiskDevice.Backing.DeviceName} | %{$_.ScsiCanonicalName} $Sheet.Cells.Item($row,2) = $CononicalName $esxCli = Get-VMHost -Name (Get-VM $VMobj.Name).VMHost | Get-EsxCli $Lun = $esxCli.storage.core.path.list() | Where-Object { $_.Device -eq $CononicalName } |Select-Object -First 1 $Sheet.Cells.Item($row,9) = $Lun.RuntimeName.Substring($Lun.RuntimeName.LastIndexof(“L”)+1) } else { $Sheet.Cells.Item($row,2) = "VMDK" } $Sheet.Cells.Item($row,3) = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB $Sheet.Cells.Item($row,4) = $VirtualDiskDevice.Backing.DeviceName $Sheet.Cells.Item($row,5) = $VirtualDiskDevice.Backing.FileName $Sheet.Cells.Item($row,6) = $VirtualDiskDevice.DeviceInfo.Label $Sheet.Cells.Item($row,7) = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)" $Sheet.Cells.Item($row,8) = $VirtualSCSIController.DeviceInfo.Label $row++ } } } Disconnect-VIServer -Server $server -Confirm:$false

 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.