VMware Cloud Community
ccatano2000
Contributor
Contributor
Jump to solution

PowerCLI rookie question about setting policy to multiple LUNS at once

Does anyone know how I can modify the below scripts to include a list of say 10 luns, rather than a single one ?

Connect-VIServer -Server ESXSERVER01 -User root -Password Password01

esxcli = Get-EsxCli

esxcli.nmp.device.setpolicy($null,"naa.600xxxxxxxxxxxxxxxxxxxx0000", "VMW_PSP_RR")

I want to be able to have it set the policy for LUNS naa.600xxxxxxxxxxxxxxxx0000 through naa.600xxxxxxxxxxxxxxxxxxxx0010 ...  How do I list them  in the script ?

would I do them semicolon seperated as such :

esxcli.nmp.device.setpolicy($null,"naa.600xxxxxxxxxxxxxxxxxxxx0000";"naa.600xxxxxxxxxxxxxxxxxxxx0001";"naa.600xxxxxxxxxxxxxxxxxxxx0002", "VMW_PSP_RR")

???

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Afaik you can only specify 1 device to the setpolicy command (similar to what you can do with the -d parameter on the esxcli command).

The best way of doing what you are trying to achieve is to use a loop over an array.

Something like this

$luns = "naa.600xxxxxxxxxxxxxxxx0000","naa.600xxxxxxxxxxxxxxxx0001","naa.600xxxxxxxxxxxxxxxx0002",
    "naa.600xxxxxxxxxxxxxxxx0003","naa.600xxxxxxxxxxxxxxxx0004","naa.600xxxxxxxxxxxxxxxx0005",
    "naa.600xxxxxxxxxxxxxxxx0006","naa.600xxxxxxxxxxxxxxxx0007","naa.600xxxxxxxxxxxxxxxx0008",
    "naa.600xxxxxxxxxxxxxxxx0009","naa.600xxxxxxxxxxxxxxxx0010"
    Connect-VIServer -Server ESXSERVER01 -User root -Password Password01
$esxcli
= Get-EsxCli $luns | %{     esxcli.nmp.device.setpolicy($null,$_, "VMW_PSP_RR") }


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Afaik you can only specify 1 device to the setpolicy command (similar to what you can do with the -d parameter on the esxcli command).

The best way of doing what you are trying to achieve is to use a loop over an array.

Something like this

$luns = "naa.600xxxxxxxxxxxxxxxx0000","naa.600xxxxxxxxxxxxxxxx0001","naa.600xxxxxxxxxxxxxxxx0002",
    "naa.600xxxxxxxxxxxxxxxx0003","naa.600xxxxxxxxxxxxxxxx0004","naa.600xxxxxxxxxxxxxxxx0005",
    "naa.600xxxxxxxxxxxxxxxx0006","naa.600xxxxxxxxxxxxxxxx0007","naa.600xxxxxxxxxxxxxxxx0008",
    "naa.600xxxxxxxxxxxxxxxx0009","naa.600xxxxxxxxxxxxxxxx0010"
    Connect-VIServer -Server ESXSERVER01 -User root -Password Password01
$esxcli
= Get-EsxCli $luns | %{     esxcli.nmp.device.setpolicy($null,$_, "VMW_PSP_RR") }


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

0 Kudos
ccatano2000
Contributor
Contributor
Jump to solution

thanks again LUCD,

So, essentially what I am doing is defining them prior to calling them from the script right ?

i use    $LUNS = "NAA1", "NAA2", "NAA3".....etc    to define the desired luns to modify,  then I call the script below which references "$LUNS="

right ?

thanks again for all your help,  I cant wait to give it a try.

chris

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is correct, you specify all LUNs in an array.

Then you iterate through the array.

Each iteration will have the element from the array in the $_ variable.

The iteration is in fac this

$luns | %{

...

}

The array ($luns) is piped (the | symbol) to the foreach loop.

The % is an alias for the foreach-object cmdlet.

Inside the loop (everything between the parenthesis) the value of the actual element for that iteration is available in the $_ variable.


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