VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

You cannot call a method on a null-valued expression

Hi

I am getting below error when I run the below script, Please help

$report = Get-Cluster |
Get-VMHost -PipelineVariable vmhost |
ForEach-Object {
$esxcli = Get-EsxCli -VMHost $vmhost -V2
Write-Host -ForegroundColor green "Server: $($vmhost.Name)"
$esxcli.storage.nmp.device.list.Invoke() | where { $_.Device -match "^eui\.\w{16}(6c9ce9|6C9CE9)\w{10}"}
$esxcli.storage.nmp.psp.roundrobin.deviceconfig.list.Invoke() | where {$_.Vendor -eq "Nimble"} | select @{N="VMHost";E={$vmhost.Name }}, Description, Name, Vendor, Model, RuleGroup, DefaultPSP, PSPOptions
}
$report

 

Output

You cannot call a method on a null-valued expression.
At D:\myreports\Multipath_Rules\1_Nimble_List_SATP_rules.ps1:43 char:5
+ $esxcli.storage.nmp.psp.roundrobin.device.list.Invoke()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

ganapa2000_0-1629356213999.png

 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You have to provide a parameter.
Create the required hash table with CreateArgs()


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

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

Is there perhaps an ESXi node in a cluster that is powered off?


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

no, all the esxi are powered on state

Tags (1)
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Does the previous line $esxcli.storage.nmp.device.list.Invoke() returns results?


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

yes, I get the output

ganapa2000_0-1629358931893.png

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Just noticed that $esxcli.storage.nmp.psp.roundrobin.deviceconfig does not have a list method.
There is only a get and set method.

 list.jpg


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

I am getting the error, when I use the get

PS D:\> $esxcli = Get-EsxCli -VMHost 10.10.10.144 -V2

PS D:\> $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get()
Method invocation failed because [VMware.VimAutomation.ViCore.Impl.V1.EsxCli.EsxCliElementImpl] does not contain a method named 'get'.
At line:1 char:1
+ $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (get:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That should be get.Invoke()


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

tried as below, still no luck

PS D:\> $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get.Invoke()
The method 'get' is invoked with '0' parameters, but the expected parameter count is '1'.
At line:1 char:1
+ $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get.Invoke()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], InvalidArgument
+ FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidArgument

 

PS D:\> $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get.Invoke($_.device)
If specified, the arguments parameter must contain a single value of type Hashtable.
At line:1 char:1
+ $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get.Invoke($_.device)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You have to provide a parameter.
Create the required hash table with CreateArgs()


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

that worked. thank you

Reply
0 Kudos