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
The object returned by Get-Harddisk does not have a ScsiCanonicalName property.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
how can I get the ScsiCanonicalName of VMdisk ?
You can find one way in Solved: Re: SCSIcanonicalname? - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
LucD,
anyway to get the localdisk serial number similar to canonical name in order to identify the disk ?
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
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
Then use the Filename
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD, Is there a way to get the UUID for local disks ?
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
The error is not on that Replace call.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
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 ?
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
Test on $null
UUID = &{if($_.Backing.UUID -ne $null){
$_.Backing.UUID.Replace('-', '')
}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference