Hi,
I am using the following script to keep track of RDMs in relation to migrations.
$DiskInfo= @()
$vm = Get-Cluster "CLUSTERNAME" | Get-VM
foreach ($VMview in Get-VM $vm | 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})) {
$VirtualDisk = "" | Select VMname, SCSIController, SCSI_ID, DiskName, DeviceName, DiskFile, DiskSize, type
$VirtualDisk.VMname = $VMview.Name
$VirtualDisk.SCSIController = $VirtualSCSIController.DeviceInfo.Label
$VirtualDisk.DiskName = $VirtualDiskDevice.DeviceInfo.Label
$VirtualDisk.SCSI_ID = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"
$VirtualDisk.DeviceName = $VirtualDiskDevice.Backing.DeviceName
$VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName
$VirtualDisk.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB
$DiskInfo += $VirtualDisk
}}}
$DiskInfo | sort VMname, Diskname | Out-GridView
Is there a way to add SCSI canonical name to this?
I am trying to wrap my head around calling these methods, is there a guide or comprehensive reference somewhere?
Try something like this
Get-View -ViewType VirtualMachine -SearchRoot $cluster.MoRef -PipelineVariable vm |
ForEach-Object -Process {
$vm.Config.Hardware.Device | where{$_ -is [VMware.Vim.VirtualSCSIController]} |
ForEach-Object -Process {
$ctrl = $_
$vm.Config.Hardware.Device | where{$ctrl.Device -contains $_.Key} |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
VMname = $vm.Name
SCSIController = $ctrl.DeviceInfo.Label
DiskName = $_.DeviceInfo.Label
SCSI_ID = "$($ctrl.BusNumber) : $($_.UnitNumber)"
DeviceName = $_.DeviceInfo.Label
DiskFile = $_.Backing.FileName
DiskSize = $_.CapacityInKB * 1KB / 1GB
DiskType = &{if($_.Backing.Gettype().Name -match 'flat'){'Flat'}
else{
if($_.Backing.CompatibilityMode -match 'physical'){'RawPhysical'}else{'RawVirtual'}
}}
CanonicalName = &{
if($_.Backing.Gettype().Name -notmatch 'flat'){
$dev = $_
$esx = Get-View -Id $vm.RunTime.Host
$lun = $esx.Config.StorageDevice.ScsiLun | where{$_.Descriptor.Id -contains $dev.Backing.DeviceName}
$lun.CanonicalName
}
}
})
}
}
#}
} | Sort-Object -Property VMname, Diskname | Out-GridView
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Get-View -ViewType VirtualMachine -SearchRoot $cluster.MoRef -PipelineVariable vm |
ForEach-Object -Process {
$vm.Config.Hardware.Device | where{$_ -is [VMware.Vim.VirtualSCSIController]} |
ForEach-Object -Process {
$ctrl = $_
$vm.Config.Hardware.Device | where{$ctrl.Device -contains $_.Key} |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
VMname = $vm.Name
SCSIController = $ctrl.DeviceInfo.Label
DiskName = $_.DeviceInfo.Label
SCSI_ID = "$($ctrl.BusNumber) : $($_.UnitNumber)"
DeviceName = $_.DeviceInfo.Label
DiskFile = $_.Backing.FileName
DiskSize = $_.CapacityInKB * 1KB / 1GB
DiskType = &{if($_.Backing.Gettype().Name -match 'flat'){'Flat'}
else{
if($_.Backing.CompatibilityMode -match 'physical'){'RawPhysical'}else{'RawVirtual'}
}}
CanonicalName = &{
if($_.Backing.Gettype().Name -notmatch 'flat'){
$dev = $_
$esx = Get-View -Id $vm.RunTime.Host
$lun = $esx.Config.StorageDevice.ScsiLun | where{$_.Descriptor.Id -contains $dev.Backing.DeviceName}
$lun.CanonicalName
}
}
})
}
}
#}
} | Sort-Object -Property VMname, Diskname | Out-GridView
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you!
For good measure, is there a way to run it per VM also? i.e. give it the VM name somehow?
I tried replacing the forst 2 lines with
$VM = get-view –viewtype VirtualMachine –filter @{“Name”=”VMNAME”}
but that leaves out the canonical name...
Replace the first 2 lines
Get-View -ViewType VirtualMachine -SearchRoot $cluster.MoRef -PipelineVariable vm |
by
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you!!