VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Error: You cannot call a method on a null-valued expression

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Wow....that worked..... thanks a lot master Smiley Happy

0 Kudos