PowerCLI

  • 1.  You cannot call a method on a null-valued expression

    Posted Aug 19, 2021 06:58 AM

    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

     



  • 2.  RE: You cannot call a method on a null-valued expression

    Posted Aug 19, 2021 07:18 AM

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



  • 3.  RE: You cannot call a method on a null-valued expression

    Posted Aug 19, 2021 07:23 AM

    no, all the esxi are powered on state



  • 4.  RE: You cannot call a method on a null-valued expression

    Posted Aug 19, 2021 07:38 AM

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



  • 5.  RE: You cannot call a method on a null-valued expression

    Posted Aug 19, 2021 07:42 AM

    yes, I get the output

    ganapa2000_0-1629358931893.png

     



  • 6.  RE: You cannot call a method on a null-valued expression

    Posted Aug 19, 2021 08:02 AM

    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



  • 7.  RE: You cannot call a method on a null-valued expression

    Posted Aug 19, 2021 08:39 AM

    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



  • 8.  RE: You cannot call a method on a null-valued expression

    Posted Aug 19, 2021 09:16 AM

    That should be get.Invoke()



  • 9.  RE: You cannot call a method on a null-valued expression

    Posted Aug 19, 2021 10:03 AM

    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



  • 10.  RE: You cannot call a method on a null-valued expression
    Best Answer

    Posted Aug 19, 2021 10:40 AM

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



  • 11.  RE: You cannot call a method on a null-valued expression

    Posted Aug 20, 2021 07:54 AM

    that worked. thank you