VMware Cloud Community
vlife201110141
Enthusiast
Enthusiast
Jump to solution

ESXCLI methods

Hello Guys,

I am totally confused with esxcli things @version 5

$esxcli = get-esxcli -vmhost $esx

$esxcli | get-member

why I do not see methods here like $esxcli.storage ... $esxcli.network .... etc

I am really upset of why this part does not work also to list all devices

$esxcli.storage.nmp.device.list() | Where {$_.StorageArrayType -eq $satp} or

$esxcli.storage.nmp.device.list($null) | Where {$_.StorageArrayType -eq $satp}

Thanks in advance,

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The $esxcli object is not you ordinary object, the "methods" are all codeproperties and/or codemethods.

The easiest way to see all calls that are available is to do

$esxcli.esxcli.command.list()

I'm not sure what you mean by the 2nd part of your question.

What do you have in the $satp variable ?

If you want to see all devices, why don't you just leave out the Where-clause ?


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

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

The $esxcli object is not you ordinary object, the "methods" are all codeproperties and/or codemethods.

The easiest way to see all calls that are available is to do

$esxcli.esxcli.command.list()

I'm not sure what you mean by the 2nd part of your question.

What do you have in the $satp variable ?

If you want to see all devices, why don't you just leave out the Where-clause ?


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

vlife201110141
Enthusiast
Enthusiast
Jump to solution

thx my mistake while coping Luc what i mean what is missing in the following script

$esxcli.storage.nmp.device.list()

$esxcli.storage.nmp.device.list($null)

Whole script what I want to do is

Add-PSsnapin VMware.VimAutomation.Core

$defaultpsp = "VMW_PSP_RR"

$psp = "VMW_PSP_RR"

$satp1 = "VMW_SATP_DEFAULT_AA"

Connect-VIServer -Server "vcenter" -User "xxx" -Password "xxx"

$esxhosts = get-cluster | Get-VMHost

foreach($esx in $esxhosts){

  $esxcli = Get-EsxCli -VMHost $esx -ErrorAction SilentlyContinue

  if($esxcli){

    $nmpdevlist = $esxcli.storage.nmp.device.list() | Where {$_.StorageArrayType -eq $satp1}

    foreach($dev in $nmpdevlist){

     $esxcli.storage.nmp.device.set($null, $dev.device, $psp) | Out-Null     

     $esxcli.storage.nmp.psp.roundrobin.deviceconfig.set($null, $dev.device, 1, "iops", $null) | Out-Null   

     }

     $esxcli.storage.nmp.satp.set($null, $defaultpsp, $satp1) | Out-Null   

     }

}

Disconnect-VIServer -Server "vcenter" -Confirm:$false

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I think we already discussed this script in another thread.

Do you get any errors ?

Is the script not doing what you intended it to do ?


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

0 Kudos
vlife201110141
Enthusiast
Enthusiast
Jump to solution

yes sir script should do what i intented to do but i couldn't resolve this error below

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

At C:\RR_test.ps1:10 char:50

+     $nmpdevlist = $esxcli.storage.nmp.device.list <<<< ($null) | Where {$_.StorageArrayType -eq $satp1}

    + CategoryInfo          : InvalidOperation: (list:String) [], RuntimeException

    + FullyQualifiedErrorId : InvokeMethodOnNull

0 Kudos
vlife201110141
Enthusiast
Enthusiast
Jump to solution

This works I would like to share it in the community also.

Add-PSsnapin VMware.VimAutomation.Core

$defaultpsp = "VMW_PSP_RR"

$psp = "VMW_PSP_RR"

$satp1 = "VMW_SATP_DEFAULT_AA"

Connect-VIServer -Server "xxx" -User "xxx" -Password "xxx"

$esxhosts = get-cluster | Get-VMHost

foreach($esx in $esxhosts){

  $esxcli = Get-EsxCli -VMHost $esx -ErrorAction SilentlyContinue

  if($esxcli){

    $nmpdevlist = $esxcli.storage.nmp.device.list() | Where {$_.StorageArrayType -eq $satp1}

    foreach($dev in $nmpdevlist){

     $esxcli.storage.nmp.device.set($false, $dev.device, $psp) | Out-Null     

     }

     $esxcli.storage.nmp.satp.set($true, $defaultpsp, $satp1) | Out-Null   

     }

}

Disconnect-VIServer -Server "xxx" -Confirm:$false

0 Kudos