VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

VM Disk NAA shows blank

Hi,

I am unable to get the VM Disk NAA as it shows blank without any error.

Please help

$result = foreach ($vms in Get-VM APP211, APP02) {
Get-VM $vms | Get-HardDisk | Select @{N='VM Name';E={$_.Parent.Name}},
@{N="IP Address";E={@($_.Parent.guest.IPAddress[0])}}, #One IP of VMs
@{N="Folder";E={$_.Parent.Folder.Name}},
@{N="Datastore";E={Get-Datastore -VM $vms}},
@{N='HD Name';E={$_.Name}},
@{N='HD Capacity';E={$_.CapacityGB}},
@{N='DiskType';E={$_.DiskType}},
@{N='HD Format';E={$_.StorageFormat}},
@{N="ScsiID";E={$strControllerKey = $_.ExtensionData.ControllerKey.ToString(); "{0}`:{1}" -f $strControllerKey[$strControllerKey.Length - 1], $_.ExtensionData.Unitnumber}},
@{N="UUID";E={$_.extensiondata.backing.uuid.Replace('-', '')}},
@{N='NAA';E={$_.ScsiCanonicalName}},
@{N='VMDKPath';E={$_.Filename}}
}
$result | Out-GridView

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That should be

UUID = $_.Backing.Uuid


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

View solution in original post

0 Kudos
20 Replies
LucD
Leadership
Leadership
Jump to solution

The object returned by Get-Harddisk does not have a ScsiCanonicalName property.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

how can I get the ScsiCanonicalName of VMdisk ?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can find one way in Solved: Re: SCSIcanonicalname? - VMware Technology Network VMTN


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I tried the script from the below link as below, even in that I am unable to get the colonicalname for local disks. If I have RDM, the below script shows the colonicalname. 

Get-View -ViewType VirtualMachine -Filter @{Name='APP02'} -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

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Local disks have no canonicalname, they sit on a datastore.
Only RDM disks will show a canonicalname.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

anyway to get the localdisk serial number similar to canonical name in order to identify the disk ?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You have the UID and the Filename to identify the vDisk, not sure what you mean by "serial number".


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

I tried as below, but UUID shows blank for local disks without any error

Get-View -ViewType VirtualMachine -Filter @{Name='DB1'} -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
}
}
UUID = $_.Backing.DeviceName
})
}
}
#}
} | Sort-Object -Property VMname, Diskname | Out-GridView

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then use the Filename


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD, Is there a way to get the UUID for local disks ?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That should be

UUID = $_.Backing.Uuid


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you LucD, now I am able to get the UUID, but If I am seeing the UUID for local disk as below

6000C29c-3906-46ff-1026-81fdcce92b56

But If I use the UUID = $_.Backing.UUID.Replace('-', '') to remove the hypens then I am getting the error as below 

You cannot call a method on a null-valued expression.
At line:20 char:33
+ CanonicalName = &{
+ ~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At line:20 char:33
+ CanonicalName = &{
+ ~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

 

 

Script

Get-View -ViewType VirtualMachine -Filter @{Name='DB1'} -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
}
}
UUID = $_.Backing.UUID.Replace('-', '')
})
}
}
} | Sort-Object -Property VMname, Diskname | Out-GridView

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The error is not on that Replace call.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you LucD. I am able to get the output but I seeing error in the output where RDM is present

You cannot call a method on a null-valued expression.
At line:28 char:10
+ UUID = $($_.Backing.UUID.Replace('-', ''))
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At line:28 char:10
+ UUID = $($_.Backing.UUID.Replace('-', ''))
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you want to do that Replace, you have to first test if there is a value in the property.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I have a VM with VMDK and RDM attached to it. UUID are available for VMDK disks and NAA is available for RDM disks. When I run the script, that replace would replace the hypen (-) for UUID since there is no UUID available for RDM, I am getting that error.

Anyway to ignore the replace for RDM disk and perform only for VMDK disks ?

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Like I said earlier, you have to test if there is a value.
Something along these lines

UUID = &{if($_.Backing.UUID -ne ''){
   $_.Backing.UUID.Replace('-', '')
}}


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

still the same error, attached the script as well

ganapa2000_0-1648184557124.png

 

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Test on $null

UUID = &{if($_.Backing.UUID -ne $null){
   $_.Backing.UUID.Replace('-', '')
}}


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

Tags (1)
0 Kudos