VMware Cloud Community
mrray
Enthusiast
Enthusiast
Jump to solution

SCSIcanonicalname?

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?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$cluster = Get-View -ViewType ClusterComputeResource -Property Name -Filter @{Name='cluster'}

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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$cluster = Get-View -ViewType ClusterComputeResource -Property Name -Filter @{Name='cluster'}

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

0 Kudos
mrray
Enthusiast
Enthusiast
Jump to solution

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...

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Replace the first 2 lines

$cluster = Get-View -ViewType ClusterComputeResource -Property Name -Filter @{Name='cluster'}

Get-View -ViewType VirtualMachine -SearchRoot $cluster.MoRef -PipelineVariable vm |

by

Get-View -ViewType VirtualMachine -Filter @{Name='vmname'} -PipelineVariable vm |


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mrray
Enthusiast
Enthusiast
Jump to solution

Thank you!!

0 Kudos