Automation

 View Only
Expand all | Collapse all

ESXCLI Storage NMP SATP Rule Script Error

  • 1.  ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 14, 2019 01:07 PM

    Hi there,

    I am running the below commands from pow

    $esxcli = Get-EsxCli -VMHost $esxhosts

    $esxcli.storage.nmp.satp.rule.remove($false,"tpgs_on","HP 3PAR Custom Rule",$null,$null,"VV",$null,"VMW_PSP_RR","iops=1","VMW_SATP_ALUA",$null,$null,"3PARdata") | Out-Null

    $esxcli.storage.nmp.satp.rule.add($false,"tpgs_on","HP 3PAR Custom Rule",$null,$null,$null,"VV",$null,"VMW_PSP_RR","iops=1","VMW_SATP_ALUA",$null,$null,"3PARdata") | Out-Null

    Error:

    PS C:\Windows\system32> $esxcli.storage.nmp.satp.rule.remove($false,"tpgs_on","HP 3PAR Custom Rule",$null,$null,"VV",$null,"VMW_PSP_RR","iops=1","VMW_SATP_ALUA",$null,$null,"3PARdata")

    Cannot find an overload for "remove" and the argument count: "13".

    At line:1 char:1

    + $esxcli.storage.nmp.satp.rule.remove($false,"tpgs_on","HP 3PAR Custom ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [], MethodException

        + FullyQualifiedErrorId : MethodCountCouldNotFindBest

    Cannot find an overload for "add" and the argument count: "14".

    At P:\Ankur\Ankur Scripts\Host-Get-AdvancedSetting-ChangeAttribute.ps1:40 char:3

    +   $esxcli.storage.nmp.satp.rule.add($false,"tpgs_on","HP 3PAR Custom  ...

    +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [], MethodException

        + FullyQualifiedErrorId : MethodCountCouldNotFindBest



  • 2.  RE: ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 14, 2019 01:25 PM

    It is much easier when you use the V2 switch.

    Then you can use the CreateArgs method to see all the parameters (required and optional).

    $esxcli = Get-EsxCli -VMHost $esxhosts -v2

    $esxcli.storage.nmp.satp.rule.remove.CreateArgs()

    You can now assign the values (note that you need to provide anything ot the optional parameters you don't use).

    $esxcli = Get-EsxCli -VMHost $esxhosts -v2

    $sRem = $esxcli.storage.nmp.satp.rule.remove.CreateArgs()

    $sRem['boot'] = $false

    ...

    The you call the Invoke method with the hash table.

    $esxcli.storage.nmp.satp.rule.remove.Invoke($sRem)

    PS: I hope you only have 1 VMHost in $esxHosts, otherwise you will have some other issues.



  • 3.  RE: ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 14, 2019 02:03 PM

    Thanks for reply

    $esxcli = Get-EsxCli -VMHost $esxhosts -v2

    $esxcli.storage.nmp.satp.rule.remove.CreateArgs()

    $esxcli.storage.nmp.satp.rule.remove($false,"tpgs_on","HP 3PAR Custom Rule",$null,$null,"VV",$null,"VMW_PSP_RR","iops=1","VMW_SATP_ALUA",$null,$null,"3PARdata") | Out-Null

    $esxcli.storage.nmp.satp.rule.add($false,"tpgs_on","HP 3PAR Custom Rule",$null,$null,$null,"VV",$null,"VMW_PSP_RR","iops=1","VMW_SATP_ALUA",$null,$null,"3PARdata")| Out-Null

    $sRem = $esxcli.storage.nmp.satp.rule.add.CreateArgs()

    $esxcli.storage.nmp.satp.rule.add($false,"tpgs_on","HP 3PAR Custom Rule",$null,$null,$null,"VV",$null,"VMW_PSP_RR","iops=1","VMW_SATP_ALUA",$null,$null,"3PARdata")| Out-Null

    $sRem['boot'] = $false = ------ what this will do . we don't want to reboot the host as we are planning to run this cmd on live hosts

    $esxcli.storage.nmp.satp.rule.remove.Invoke($sRem)

    Does the above will work LucD



  • 4.  RE: ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 14, 2019 02:13 PM

    No, you have to fill in all the hash entries (the optional ones that you want and the required ones).

    The 'boot' entry was just 1 example, you'll have to the other as well.

    Then you use the remove.Invoke($sRem) as I showed in the samepl code.

    No more passing all the parameters on the method itself.

    You find a more elaborate explanation on how to work with the V2 switch in PowerCLI 6.3 R1: Get-ESXCLI Why the V2?



  • 5.  RE: ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 14, 2019 02:15 PM

    Hi LucD,

    Below is my complete script which the changes you mentioned. Does this looks correct.

    $VC = read-host "Please enter vCenter Name"

    connect-viserver $VC

    $esxHosts = Get-Content -Path C:\Scripts\HostName.txt

    $esxcli = Get-EsxCli -VMHost $esxhosts -V2

    foreach($esx in $esxHosts)

    {

       Get-AdvancedSetting -Entity $esx -Name Disk.QFullSampleSize | Set-AdvancedSetting -Value '32' -Confirm:$false |Select Entity,Name,Value | Export-CSV -NoTypeInformation -Append -path c:\scripts\ADSettingsChnage.csv

       Get-AdvancedSetting -Entity $esx -Name Disk.QFullThreshold| Set-AdvancedSetting -Value '4' -Confirm:$false |Select Entity,Name,Value | Export-CSV -NoTypeInformation -Append -path c:\scripts\ADSettingsChnage.csv

      Get-AdvancedSetting -Entity $esx -Name Disk.EnableNaviReg| Set-AdvancedSetting -Value '0' -Confirm:$false |Select Entity,Name,Value | Export-CSV -NoTypeInformation -Append -path c:\scripts\ADSettingsChnage.csv

       

      Get-AdvancedSetting -Entity $esx -Name Disk.ReqCallThreshold| Set-AdvancedSetting -Value '30' -Confirm:$false |Select Entity,Name,Value | Export-CSV -NoTypeInformation -Append -path c:\scripts\ADSettingsChnage.csv

    Get-AdvancedSetting -Entity $esx -Name VMFS3.UseATSForHBOnVMFS5 | Set-AdvancedSetting -Value '0' -Confirm:$false |Select Entity,Name,Value | Export-CSV -NoTypeInformation -Append -path c:\scripts\ADSettingsChnage.csv

    $sRem=  $esxcli.storage.nmp.satp.rule.remove.CreateArgs($false,"tpgs_on","HP 3PAR Custom Rule",$null,$null,"VV",$null,"VMW_PSP_RR","iops=1","VMW_SATP_ALUA",$null,$null,"3PARdata") | Out-Null

    $sAdd= $esxcli.storage.nmp.satp.rule.add.CreateArgs($false,"tpgs_on","HP 3PAR Custom Rule",$null,$null,$null,"VV",$null,"VMW_PSP_RR","iops=1","VMW_SATP_ALUA",$null,$null,"3PARdata")| Out-Null

    $esxcli.storage.nmp.satp.rule.remove.Invoke($sRem) |Export-CSV -NoTypeInformation -Append -path c:\scripts\Remove-Rule.csv

    $esxcli.storage.nmp.satp.rule.remove.Invoke($sAdd) | Export-CSV -NoTypeInformation -Append -path c:\scripts\Add-Rule.csv

    }



  • 6.  RE: ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 14, 2019 02:46 PM

    No, like this

    $sRem = $esxcli.storage.nmp.satp.rule.remove.CreateArgs()

    $sRem['boot'] = $false

    $sREm['claimoption'] = 'tpgs_on'

    $sREm['description'] = 'HP 3PAR Custom Rule'

    $sREm['model'] = 'VV'

    $sREm['psp'] = 'VMW_PSP_RR'

    $sREm['psoption'] = 'iops=1'

    $sREm['satp'] = 'VMW_SATP_ALUA'

    $sREm['vendor'] = '3PARdata'

    $esxcli.storage.nmp.satp.rule.remove.Invoke($sRem)


    $sAdd = $esxcli.storage.nmp.satp.rule.add.CreateArgs()

    $sAdd['boot'] = $false

    $sAdd['claimoption'] = 'tpgs_on'

    $sAdd['description'] = 'HP 3PAR Custom Rule'

    $sAdd['model'] = 'VV'

    $sAdd['psp'] = 'VMW_PSP_RR'

    $sAdd['psoption'] = 'iops=1'

    $sAdd['satp'] = 'VMW_SATP_ALUA'

    $sAdd['vendor'] = '3PARdata'

    $esxcli.storage.nmp.satp.rule.add.Invoke($sAdd)



  • 7.  RE: ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 15, 2019 01:03 PM

    Hi LucD,

    Thanks for your help when i ran the below.

    #$VC = read-host "Please enter vCenter Name"

    #connect-viserver $VC

    $esxhosts = Get-Content -Path C:\Scripts\HostName.txt

    $esxcli = Get-EsxCli -VMHost $esxhosts -V2

    foreach($esx in $esxhosts)

    {

    $sRem = $esxcli.storage.nmp.satp.rule.remove.CreateArgs()

    $sRem['boot'] = $false

    $sREm['claimoption'] = 'tpgs_on'

    $sREm['description'] = 'HP 3PAR Custom Rule'

    $sREm['model'] = 'VV'

    $sREm['psp'] = 'VMW_PSP_RR'

    $sREm['psoption'] = 'iops=1'

    $sREm['satp'] = 'VMW_SATP_ALUA'

    $sREm['vendor'] = '3PARdata'

    $esxcli.storage.nmp.satp.rule.remove.Invoke($sRem)

    $sAdd = $esxcli.storage.nmp.satp.rule.add.CreateArgs()

    $sAdd['boot'] = $false

    $sAdd['claimoption'] = 'tpgs_on'

    $sAdd['description'] = 'HP 3PAR Custom Rule'

    $sAdd['model'] = 'VV'

    $sAdd['psp'] = 'VMW_PSP_RR'

    $sAdd['psoption'] = 'iops=1'

    $sAdd['satp'] = 'VMW_SATP_ALUA'

    $sAdd['vendor'] = '3PARdata'

    $esxcli.storage.nmp.satp.rule.add.Invoke($sAdd)

    }

    Output Error: Am i missing something?

    Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

    At line:21 char:1

    + $esxcli.storage.nmp.satp.rule.remove.Invoke($sRem)

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : OperationStopped: (:) [], FormatException

        + FullyQualifiedErrorId : System.FormatException

    Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

    At line:35 char:1

    + $esxcli.storage.nmp.satp.rule.add.Invoke($sAdd)

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : OperationStopped: (:) [], FormatException

        + FullyQualifiedErrorId : System.FormatException



  • 8.  RE: ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 15, 2019 01:08 PM

    You have to assign the $esxcli for each ESXi node separately (see my earlier remark).

    Move that assignment within the ForEach loop

    $esxcli = Get-EsxCli -VMHost $esx -V2



  • 9.  RE: ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 15, 2019 01:59 PM

    Thanks you so much again for helping with this. Its giving the results as True and marked as green.  :smileyhappy:

    The last thing i wanted is the output in the below manner

    Desired output in the CSV format :

    Host Name            Remove_Rule                     ADD_Rule       

    XYZ                              True                                   True

    I tried below but did not gave desired result

    Select @{N='VMHost';E={$esxcli.VMHost.Name}}, @{N='Remove_Rule';E={$esxcli.storage.nmp.satp.rule.remove.Invoke($sRem)}}

    Select @{N='VMHost';E={$esxcli.VMHost.Name}}, @{N='Add Rule';E={$esxcli.storage.nmp.satp.rule.add.Invoke($sAdd)}}

    Which did not result anything.

    PS C:\Windows\system32>

    #$VC = read-host "Please enter vCenter Name"

    #connect-viserver $VC

    $esxhosts = Get-Content -Path C:\Scripts\HostName.txt

    foreach($esx in $esxhosts){

    $esxcli = Get-EsxCli -VMHost $esxhosts -V2

    $sRem = $esxcli.storage.nmp.satp.rule.remove.CreateArgs()

    $sRem['boot'] = $false

    $sREm['claimoption'] = 'tpgs_on'

    $sREm['description'] = 'HP 3PAR Custom Rule'

    $sREm['model'] = 'VV'

    $sREm['psp'] = 'VMW_PSP_RR'

    $sREm['pspoption'] = 'iops=1'

    $sREm['satp'] = 'VMW_SATP_ALUA'

    $sREm['vendor'] = '3PARdata'

    $esxcli.storage.nmp.satp.rule.remove.Invoke($sRem)

    $sAdd = $esxcli.storage.nmp.satp.rule.add.CreateArgs()

    $sAdd['boot'] = $false

    $sAdd['claimoption'] = 'tpgs_on'

    $sAdd['description'] = 'HP 3PAR Custom Rule'

    $sAdd['model'] = 'VV'

    $sAdd['psp'] = 'VMW_PSP_RR'

    $sAdd['pspoption'] = 'iops=1'

    $sAdd['satp'] = 'VMW_SATP_ALUA'

    $sAdd['vendor'] = '3PARdata'

    $esxcli.storage.nmp.satp.rule.add.Invoke($sAdd)

    }

    true

    true

    PS C:\Windows\system32>



  • 10.  RE: ESXCLI Storage NMP SATP Rule Script Error
    Best Answer

    Posted Jan 15, 2019 02:19 PM

    You had the incorrect variable in the VMHost parameter.

    Try like this

    $esxhosts = Get-Content -Path C:\Scripts\HostName.txt


    foreach ($esx in $esxhosts) {

       $esxcli = Get-EsxCli -VMHost $esx -V2


       $sRem = $esxcli.storage.nmp.satp.rule.remove.CreateArgs()

       $sRem['boot'] = $false

       $sREm['claimoption'] = 'tpgs_on'

       $sREm['description'] = 'HP 3PAR Custom Rule'

       $sREm['model'] = 'VV'

       $sREm['psp'] = 'VMW_PSP_RR'

       $sREm['pspoption'] = 'iops=1'

       $sREm['satp'] = 'VMW_SATP_ALUA'

       $sREm['vendor'] = '3PARdata'


       $removeResult = $esxcli.storage.nmp.satp.rule.remove.Invoke($sRem)


       $sAdd = $esxcli.storage.nmp.satp.rule.add.CreateArgs()

       $sAdd['boot'] = $false

       $sAdd['claimoption'] = 'tpgs_on'

       $sAdd['description'] = 'HP 3PAR Custom Rule'

       $sAdd['model'] = 'VV'

       $sAdd['psp'] = 'VMW_PSP_RR'

       $sAdd['pspoption'] = 'iops=1'

       $sAdd['satp'] = 'VMW_SATP_ALUA'

       $sAdd['vendor'] = '3PARdata'


       $addResult = $esxcli.storage.nmp.satp.rule.add.Invoke($sAdd)


       "" | Select @{N='VMHost';E={$esxcli.VMHost.Name}},

       @{N='Remove_Rule';E={$removeResult}},

       @{N='Add_Rule';E={$addResult}}

    }



  • 11.  RE: ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 15, 2019 04:33 PM

    You helped me alot and many many thanks for that. As i am still learning the art. plz help me with the correct format

    below is the output

    PS C:\Windows\system32> P:\Ankur\Ankur Scripts\Storage-SATP-Rule-Remove-Add-Multi.ps1

    true

    true

    VMHost                        Remove_Rule Add_Rule

    ------                        ----------- --------

    usnencpe101.nmcorp.nissan.biz                    

    true

    true

    VMHost                        Remove_Rule Add_Rule

    ------                        ----------- --------

    usnencpe102.nmcorp.nissan.biz             

    I also tried with this

      "" | Select @{N='VMHost';E={$esxcli.VMHost.Name}}, @{N='Remove_Rule';E={$removeResult}},@{N='Add_Rule';E={$addResult}} |Export-Csv -Append  C:\Scripts\StorageRule-Remove-Add.csv

    Its generating the csv and the host name are also visble but no data in Remoev_rule and Add_Rule column.



  • 12.  RE: ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 15, 2019 04:51 PM

    You were not using the last version of the script I included.

    In there I intercept those $true values in 2 variables.

    A ForEach does not place any thing on the pipeline, one solution is to capture the output of the Select-Object in an array.
    And then export that array when the ForEach loop completes.

    $esxhosts = Get-Content -Path C:\Scripts\HostName.txt


    $report = foreach ($esx in $esxhosts) {

       $esxcli = Get-EsxCli -VMHost $esx -V2


       $sRem = $esxcli.storage.nmp.satp.rule.remove.CreateArgs()

       $sRem['boot'] = $false

       $sREm['claimoption'] = 'tpgs_on'

       $sREm['description'] = 'HP 3PAR Custom Rule'

       $sREm['model'] = 'VV'

       $sREm['psp'] = 'VMW_PSP_RR'

       $sREm['pspoption'] = 'iops=1'

       $sREm['satp'] = 'VMW_SATP_ALUA'

       $sREm['vendor'] = '3PARdata'


       $removeResult = $esxcli.storage.nmp.satp.rule.remove.Invoke($sRem)


       $sAdd = $esxcli.storage.nmp.satp.rule.add.CreateArgs()

       $sAdd['boot'] = $false

       $sAdd['claimoption'] = 'tpgs_on'

       $sAdd['description'] = 'HP 3PAR Custom Rule'

       $sAdd['model'] = 'VV'

       $sAdd['psp'] = 'VMW_PSP_RR'

       $sAdd['pspoption'] = 'iops=1'

       $sAdd['satp'] = 'VMW_SATP_ALUA'

       $sAdd['vendor'] = '3PARdata'


       $addResult = $esxcli.storage.nmp.satp.rule.add.Invoke($sAdd)


       "" | Select @{N = 'VMHost'; E = {$esxcli.VMHost.Name}},

       @{N = 'Remove_Rule'; E = {$removeResult}},

       @{N = 'Add_Rule'; E = {$addResult}}

    }


    $report | Export-Csv -Append C:\Scripts\StorageRule-Remove-Add.csv -NoTypeInformation -UseCulture



  • 13.  RE: ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 15, 2019 06:25 PM

    My Bad i missed to add the $removeAdd = ,$removeResult =

    Your script made my work easy. thanks a million.

    I wanted to learn this scripting skills. do you suggest any proper channel for me , so that i can do at least good in this.I am really interested and eager to learn. Once again thanks.



  • 14.  RE: ESXCLI Storage NMP SATP Rule Script Error

    Posted Jan 15, 2019 06:28 PM

    There are some rather good posts by CRazyConsultant on how to learn PowerShell and PowerCLI.

    PowerShell study guide – core concepts

    PowerCLI study guide – core concepts