mrray
Enthusiast
Enthusiast

SCSICanonicalName in output

Jump to solution

Hi,

I struggle to make friends with Get-View...

Feeling dumber than usual, trying to add a SCSICanonicalName to the output of this script:

 

$DiskInfo= @()

foreach ($VMview in Get-VM SQLCUSTERVM001 | 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, DiskName, SCSI_ID, DeviceName, DiskFile, DiskSize

$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

#Export-Csv -Path 'd:DiskInfo.csv'

# You can also use FT -AutoSize or Out-GridView if it helps

 

I am sure this will take someone smarter than me about 30 seconds..?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

The NAA (Network Addressing Authority identifier) is the preferred standard, and it is the name that comes from the storage device.
It is also the field you will find in that CanonicalName property.
The VML identifier is a legacy name generated by ESXi.

Your Storage Admins probably want to know the NAA name.

But you can have both in a report

$DiskInfo = @()
foreach ($VMview in Get-VM ERFWPCL07CN01 | 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, DiskName, SCSI_ID, DeviceName, DeviceNameVML, DiskFile, DiskSize
            $VirtualDisk.VMname = $VMview.Name
            $VirtualDisk.SCSIController = $VirtualSCSIController.DeviceInfo.Label
            $VirtualDisk.DiskName = $VirtualDiskDevice.DeviceInfo.Label
            $VirtualDisk.SCSI_ID = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"
            $VirtualDisk.DeviceName = ((Get-View -Id $vmView.Runtime.Host).Config.StorageDevice.ScsiLun | where { $_.Descriptor.Id -contains $VirtualDiskDevice.Backing.DeviceName }).CanonicalName
            $VirtualDisk.DeviceNameVML = ($esx.ExtensionData.Config.StorageDevice.ScsiLun | where { $_.Descriptor.Id -contains $VirtualDiskDevice.Backing.DeviceName }).Descriptor.Id.where{ $_ -match '^vml\.' }
            $VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName
            $VirtualDisk.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB
            $DiskInfo += $VirtualDisk
        }
    }
}
$DiskInfo | sort VMname, Diskname | Out-GridView

  
Further info on these names can be found in Storage Device Names and Identifiers


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership

Not sure what exactly you mean by the CanonicalName in this case.
Is this for RDM disks?


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

0 Kudos
mrray
Enthusiast
Enthusiast

By canonicalName I mean the naa.600xxxxxxxx

And yes, these are RDM disks.

0 Kudos
LucD
Leadership
Leadership

Ok, in that case you could do something like the following.
But note, that only RDM disks will show a CanonicalName

$DiskInfo = @()
foreach ($VMview in Get-VM ERFWPCL07CN01 | 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, DiskName, SCSI_ID, DeviceName, DiskFile, DiskSize
            $VirtualDisk.VMname = $VMview.Name
            $VirtualDisk.SCSIController = $VirtualSCSIController.DeviceInfo.Label
            $VirtualDisk.DiskName = $VirtualDiskDevice.DeviceInfo.Label
            $VirtualDisk.SCSI_ID = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"
            $VirtualDisk.DeviceName = ((Get-View -Id $vmView.Runtime.Host).Config.StorageDevice.ScsiLun | where { $_.Descriptor.Id -contains $VirtualDiskDevice.Backing.DeviceName }).CanonicalName
            $VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName
            $VirtualDisk.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB
            $DiskInfo += $VirtualDisk
        }
    }
}
$DiskInfo | sort VMname, Diskname | Out-GridView


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

0 Kudos
mrray
Enthusiast
Enthusiast

Thank you, that works.

I do, however, have one question:

Do I have to choose if I want the $VirtualVisk.DeviceName to be in the format of the naa.600xxxxxx or vml.600xxxxx, or is there a way to do both?

0 Kudos
LucD
Leadership
Leadership

The NAA (Network Addressing Authority identifier) is the preferred standard, and it is the name that comes from the storage device.
It is also the field you will find in that CanonicalName property.
The VML identifier is a legacy name generated by ESXi.

Your Storage Admins probably want to know the NAA name.

But you can have both in a report

$DiskInfo = @()
foreach ($VMview in Get-VM ERFWPCL07CN01 | 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, DiskName, SCSI_ID, DeviceName, DeviceNameVML, DiskFile, DiskSize
            $VirtualDisk.VMname = $VMview.Name
            $VirtualDisk.SCSIController = $VirtualSCSIController.DeviceInfo.Label
            $VirtualDisk.DiskName = $VirtualDiskDevice.DeviceInfo.Label
            $VirtualDisk.SCSI_ID = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"
            $VirtualDisk.DeviceName = ((Get-View -Id $vmView.Runtime.Host).Config.StorageDevice.ScsiLun | where { $_.Descriptor.Id -contains $VirtualDiskDevice.Backing.DeviceName }).CanonicalName
            $VirtualDisk.DeviceNameVML = ($esx.ExtensionData.Config.StorageDevice.ScsiLun | where { $_.Descriptor.Id -contains $VirtualDiskDevice.Backing.DeviceName }).Descriptor.Id.where{ $_ -match '^vml\.' }
            $VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName
            $VirtualDisk.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB
            $DiskInfo += $VirtualDisk
        }
    }
}
$DiskInfo | sort VMname, Diskname | Out-GridView

  
Further info on these names can be found in Storage Device Names and Identifiers


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

View solution in original post

0 Kudos
mrray
Enthusiast
Enthusiast

Thank you!!

0 Kudos