I am getting below error while executing the attached script, please help
You cannot call a method on a null-valued expression.
At D:\get_drive.ps1:75 char:54
+ $vmDisk = $vm | Get-HardDisk | Where-Object {$_.ExtensionData.backing.uu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
please help
And that explains why you get the error.
Hard disk 4 doesn't have a UUID it seems, and calling the Replace method on a $null value gives that error.
You could try to avoid the problem by replacing that line with
$vmDisk = $vm | Get-HardDisk | Where-Object {$_.ExtensionData.backing.uuid -and $_.ExtensionData.backing.uuid.replace("-","") -eq $VMdiskSerialNumber.SerialNumber}
And this proves the point I have been making since a long time once again, there is no fool-proof method to map guest OS partitions to VMDK :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What does this return?
Get-VM -Name vcntrapp01 | Get-HardDisk | Select Name,@{N='UUID';E={$_.ExtensionData.backing.uuid}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Below is the output
PS D:\> Get-VM -Name vcntrapp01 | Get-HardDisk | Select Name,@{N='UUID';E={$_.ExtensionData.backing.uuid}}
Name UUID
---- ----
Hard disk 1 6000C290-d1fc-72e1-0afa-6a5e8361c76f
Hard disk 2 6000C29d-f5b5-c448-13cc-a905a88b93ef
Hard disk 3 6000C295-a567-56aa-4504-6d1b34ea0d09
Hard disk 4
And that explains why you get the error.
Hard disk 4 doesn't have a UUID it seems, and calling the Replace method on a $null value gives that error.
You could try to avoid the problem by replacing that line with
$vmDisk = $vm | Get-HardDisk | Where-Object {$_.ExtensionData.backing.uuid -and $_.ExtensionData.backing.uuid.replace("-","") -eq $VMdiskSerialNumber.SerialNumber}
And this proves the point I have been making since a long time once again, there is no fool-proof method to map guest OS partitions to VMDK :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Wow....that worked..... thanks a lot master