VMware Cloud Community
cgarciamoran
Contributor
Contributor
Jump to solution

$esxcli to change IOPS value?

So im trying to change the IOPS value to "1" it seems im on the right track by looking at some other scripts that had somethin similar, but mine doesnt seem to loop the entire cluster , look like it does but only the last host gets the updated values, so what am I missing here?

Is there a good practive snippet of code to connect to a VC, get hosts on a Cluster / Datacenter and then execute agaisnt them? Id like to be able to keep a good working code and then re using it on all my scripts? Now that I see this error Im curious if I was fooled into thinking my other scripts were working on all hosts in a Cluster not just, what's a good way to verify that?

Thx!

## Script Variables
$VC = Read-Host 'Please Enter VirtualCenter Name'
$mycluster = Read-Host 'Please Enter The Cluster Name or DataCenter'
$DiskID = "naa.600"
$esxlogin = Get-Credential
### Connect to VC and get ESX hosts per named cluster
Connect-VIServer $VC | Out-Null
foreach ($esx in Get-Cluster $mycluster | Get-VMHost) {
Connect-VIServer $esx -Credential | Out-Null
}
#Retrieve the esxcli instances and loop through them
foreach($esxcli in Get-EsxCli) {
$esxcli.system.hostname.get()
     $esxcli.storage.nmp.device.list() | where {$_.Device -match $DiskID} | % {
$esxcli.storage.nmp.psp.roundrobin.deviceconfig.set($null,$_.Device,[long]1,"iops",$false)
         
}
#Disconnect from ESX hosts
foreach ($esx in Get-Cluster $mycluster | Get-VMHost) {
Disconnect-VIServer $esx.name -Confirm:$false
}
#Disconnect from vCenter
Disconnect-VIServer $VC -Confirm:$false | Out-Null
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Do you get the same behaviour (blank screen) when you run the script directly from the PowerCLI prompt ?

This might be a PowerGui phenomena


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

View solution in original post

0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

It looks as if you are not running PowerCLI in "multiple" mode but in "single" mode.

In that case any cmdlet you execute will only be against the last connection you made.

Use the Set-PowerCLIConfiguration cmdlet to change to "multiple" mode.

Btw, in the latest PowerCLI build you do not need to connect to the ESXi anymore.

A connection to the vCenter will suffice.

Just add the VMHost parameter on the Get-EsxCli cmdlet.


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

cgarciamoran
Contributor
Contributor
Jump to solution

I'll give that a try, I do get the hostname's on the loop though? would that be a good indication that the script is running right?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, the script is running.

But since you are in "single" mode, the Get-EsxCli will only return an object for the last ESXi you connected to.

Think of it as a kind of stack.

Each Connect places an object on the stack.

In "single" mode you get the element at the top of the stack, in "multiple" mode you get all the elements on the stack.


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

0 Kudos
cgarciamoran
Contributor
Contributor
Jump to solution

Hmm It seems Im set to multiple , when I do a get config my values are

Proxypolicy -- use system policy

Default Server Mode -- Mutiple

Invalid Certificate action -- Unset

I'll have to double check the script and the devices im trying to modify, must be missing something right?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can check by displaying the variable $global:defaultviservers to which servers you are connected.


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

0 Kudos
cgarciamoran
Contributor
Contributor
Jump to solution

All right so I changed some things around and this one seems to work fine, I SSH'ed  to all hosts in a cluster and ran the script, prior to running I had 10-12 values of IOPS=1000 and once I ran it I only had the ones that are part of the controller so I think Im good. I am running / veryfing on all the other clusters

here's the modded one, I took out the direct connection the the hosts as you mentioned. My only question is that the commented piece on the for loop $esxcli.system.hostname.get() doesnt seem to work right for me. if I add it the rest of the script comes out blank on the console. How should commands be separated? Must buy and read a good CLI book Smiley Happy

## Script Variables
$VC = Read-Host 'Please Enter VirtualCenter Name'
$mycluster = Read-Host 'Please Enter The Cluster Name or DataCenter'
$DiskID = "naa.600"
### Connect to VirtualCenter
Connect-VIServer $VC | Out-Null
### Loop Through Cluster or DC to get ESXCLI instances and run commands
$esxHosts = Get-VMHost -Location $mycluster | Sort Name
foreach($esx in $esxHosts)
{
     ### $esxcli.system.hostname.get() ###
$esxcli = Get-EsxCli -VMHost $esx
     $esxcli.storage.nmp.device.list() | where {$_.Device -match $DiskID}| % {$esxcli.storage.nmp.psp.roundrobin.deviceconfig.set($null,$_.Device,1,"iops",$null) }
}
#Disconnect from VirtualCenter
Disconnect-VIServer $VC -Confirm:$false | Out-Null
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect you are not using PowerCLI 5.* in vSphere 5.*.

Do a

Get-PowerCLIVersion

to check.

The commands available have changed between 4.* and 5.*.

That commented line is syntax for version 5.*

The other is for version 4.*


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

0 Kudos
cgarciamoran
Contributor
Contributor
Jump to solution

Here's what Im using , also I use Powergui version 3.2.0.2237 as my editor, My VC and Hosts are the Latest 5 version with patches.

So I should make sure that I dont mix commands version wise?

PowerCLI Version
----------------
   VMware vSphere PowerCLI 5.0.1 build 581491
---------------
Snapin Versions
---------------
   VMware AutoDeploy PowerCLI Component 5.0 build 544967
   VMware ImageBuilder PowerCLI Component 5.0 build 544967
   VMware vCloud Director PowerCLI Component 1.5 build 581492
   VMware License PowerCLI Component 5.0 build 544881
   VMware vSphere PowerCLI Component 5.0 build 581435
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That's the latest version.

Are you sure that the ESXi that gave the error on that line is on ESXi 5.* ?

Because that line should work with PowerCLI 5.0.1 and against an ESXi 5.* server.


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

0 Kudos
cgarciamoran
Contributor
Contributor
Jump to solution

Yeah everything is 5.x latest on our enviroment, it's odd though I reran it and it works fine , I get the hostname followed by a bunch of "true" in between each host. So that's good it seems, now If I take the exact same script and do this on the foor loop

$esxcli.system.hostname.get()
$esxcli = Get-EsxCli -VMHost $esx
$esxcli.storage.nmp.device.list() | where {$_.PathSelectionPolicyDeviceConfig -match 'iops=1000'}
I get hostnames then blank screen the another hostname, if I comment the 1st line I get the results I need. I'll keep working with it Smiley Happy Do you have a 5.0 book coming? I did check out amazon but the current one is 4.x?
thx for all the help
Carlos
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you get the same behaviour (blank screen) when you run the script directly from the PowerCLI prompt ?

This might be a PowerGui phenomena


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

0 Kudos
cgarciamoran
Contributor
Contributor
Jump to solution

You Sir are a genius Smiley Happy , so it turns out it's an issue with the powergui console Hah, I never would have thought that, I'll start running my scripts through the actual powercli console and just use powergui as my editor

Thx!

0 Kudos