VMware Cloud Community
weaverj
Contributor
Contributor
Jump to solution

Script for setting IOPS=1 with Reporting

I've cobbled together this script from the ones I've found online.  The script sets everything I want correctly in our 5.0u3 env (I have a separate one for our 5.1 Lab) for our FA EMC-VMAX storage.  I would like a better report for the output though.  The Export-CSV doesn't Append yet so I'm looking for options on putting the output into a table or compiling them into a csv for review after it's been run.

## Script Variables

$VC = Read-Host 'Please Enter VirtualCenter Name'

$mycluster = Read-Host 'Please enter Cluster Name'

$DiskID = "naa.600*"

$psp = "VMW_PSP_RR"

### Connect to VirtualCenter

Connect-VIServer $VC -Protocol https -User "$admin" | 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)

{

  Write-Host $esx #Display host Name

  $csvfile = "H:\" + $esx + "_set_iops.csv" #Create file for Host Export

  ### $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)|Out-Null

  ###Display IOPS

  $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get($_.device) | Format-Table -AutoSize

  #$esxcli.storage.nmp.psp.roundrobin.deviceconfig.get($_.device) | Export-csv $csvfile -NoTypeInformation #Commented out-Needs work for output as a table.

          }

###Change the default PSP

$esxcli.storage.nmp.satp.set($null,”VMW_PSP_RR”,”VMW_SATP_SYMM”)

}

#Disconnect from VirtualCenter

Disconnect-VIServer $VC -Confirm:$false | Out-Null

Current output overwrites the CSV for each Datastore on each host, so I only get the last Datastore ran.  I understand why, just not sure the best way to modify it to move forward.

Current output:

ByteLimitDeviceIOOperationLimitLimitTypeUseActiveUnoptimizedPaths
10485760naa.60000xxxxxxxxxxxxxxxxxxxxxx1IopsFALSE
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

## Script Variables

$VC = Read-Host 'Please Enter VirtualCenter Name'

$mycluster = Read-Host 'Please enter Cluster Name'

$DiskID = "naa.600*"

$psp = "VMW_PSP_RR"

### Connect to VirtualCenter

Connect-VIServer $VC -Protocol https -User "$admin" | Out-Null

$report = @()

### Loop Through Cluster or DC to get ESXCLI instances and run commands

$esxHosts = Get-VMHost -Location $mycluster | Sort Name

foreach($esx in $esxHosts)

{

  Write-Host $esx #Display host Name

  $csvfile = "H:\" + $esx + "_set_iops.csv" #Create file for Host Export

  ### $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)|Out-Null

    ###Display IOPS

    $report += $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get($_.device) |

        Add-Member -Name Host -Value $esx.Name -MemberType NoteProperty -PassThru

  }

  ###Change the default PSP

  $esxcli.storage.nmp.satp.set($null,”VMW_PSP_RR”,”VMW_SATP_SYMM”)

}

$report | Select Host,Device,ByteLimit,IOOperationLimit,LimitType,UseActiveUnoptimizedPaths |

Export-csv $csvfile -NoTypeInformation

#Disconnect from VirtualCenter

Disconnect-VIServer $VC -Confirm:$false | Out-Null


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

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

You have the Export-Csv inside the inner loop, but you knew that of course.

A solution could be to capture the output in an array, and then at the end of the script export that array to a CSV file.

Something like this

## Script Variables

$VC = Read-Host 'Please Enter VirtualCenter Name'

$mycluster = Read-Host 'Please enter Cluster Name'

$DiskID = "naa.600*"

$psp = "VMW_PSP_RR"

### Connect to VirtualCenter

Connect-VIServer $VC -Protocol https -User "$admin" | Out-Null

$report = @()

### Loop Through Cluster or DC to get ESXCLI instances and run commands

$esxHosts = Get-VMHost -Location $mycluster | Sort Name

foreach($esx in $esxHosts)

{

  Write-Host $esx #Display host Name

  $csvfile = "H:\" + $esx + "_set_iops.csv" #Create file for Host Export

  ### $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)|Out-Null

    ###Display IOPS

    $report += $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get($_.device)

  }

  ###Change the default PSP

  $esxcli.storage.nmp.satp.set($null,”VMW_PSP_RR”,”VMW_SATP_SYMM”)

}

$report | Export-csv $csvfile -NoTypeInformation

#Disconnect from VirtualCenter

Disconnect-VIServer $VC -Confirm:$false | Out-Null


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

0 Kudos
weaverj
Contributor
Contributor
Jump to solution

Great! 

Next on my list is to add host name to the first field of each line of the array (or a new line with the name when it changes hosts)

LucD
Leadership
Leadership
Jump to solution

Try like this

## Script Variables

$VC = Read-Host 'Please Enter VirtualCenter Name'

$mycluster = Read-Host 'Please enter Cluster Name'

$DiskID = "naa.600*"

$psp = "VMW_PSP_RR"

### Connect to VirtualCenter

Connect-VIServer $VC -Protocol https -User "$admin" | Out-Null

$report = @()

### Loop Through Cluster or DC to get ESXCLI instances and run commands

$esxHosts = Get-VMHost -Location $mycluster | Sort Name

foreach($esx in $esxHosts)

{

  Write-Host $esx #Display host Name

  $csvfile = "H:\" + $esx + "_set_iops.csv" #Create file for Host Export

  ### $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)|Out-Null

    ###Display IOPS

    $report += $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get($_.device) |

        Add-Member -Name Host -Value $esx.Name -MemberType NoteProperty -PassThru

  }

  ###Change the default PSP

  $esxcli.storage.nmp.satp.set($null,”VMW_PSP_RR”,”VMW_SATP_SYMM”)

}

$report | Select Host,Device,ByteLimit,IOOperationLimit,LimitType,UseActiveUnoptimizedPaths |

Export-csv $csvfile -NoTypeInformation

#Disconnect from VirtualCenter

Disconnect-VIServer $VC -Confirm:$false | Out-Null


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

0 Kudos
weaverj
Contributor
Contributor
Jump to solution

Works perfectly!  I changed the variable for the file name to the Cluster instead of the Host name.

Here is the one for 5.0

## Script Variables

$VC = Read-Host 'Please Enter VirtualCenter Name'

$mycluster = Read-Host 'Please enter Cluster Name'

$DiskID = "naa.600009*"

$psp = "VMW_PSP_RR"

### Connect to VirtualCenter

Connect-VIServer $VC -Protocol https -User "$admin" | Out-Null

$report = @()

### Loop Through Cluster or DC to get ESXCLI instances and run commands

$esxHosts = Get-VMHost -Location $mycluster | Sort Name

foreach($esx in $esxHosts)

{

  Write-Host $esx #Display host Name

  $csvfile = "H:\" + $mycluster + "_set_iops.csv" #Create file for Host Export

  ### $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)|Out-Null

    ###Display IOPS

    $report += $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get($_.device) |

        Add-Member -Name Host -Value $esx.Name -MemberType NoteProperty -PassThru

  }

  ###Change the default PSP

  $esxcli.storage.nmp.satp.set($null,”VMW_PSP_RR”,”VMW_SATP_SYMM”)

}

$report | Select Host,Device,ByteLimit,IOOperationLimit,LimitType,UseActiveUnoptimizedPaths |

Export-csv $csvfile -NoTypeInformation

#Disconnect from VirtualCenter

Disconnect-VIServer $VC -Confirm:$false | Out-Null

and for 5.1

## Script Variables

$VC = Read-Host 'Please Enter VirtualCenter Name'

$mycluster = Read-Host 'Please enter Cluster Name'

$DiskID = "naa.600009*"

$psp = "VMW_PSP_RR"

### Connect to VirtualCenter

Connect-VIServer $VC -Protocol https -User "$admin" | Out-Null

$report = @()

### Loop Through Cluster or DC to get ESXCLI instances and run commands

$esxHosts = Get-VMHost -Location $mycluster | Sort Name

$csvfile = "H:\" + $mycluster + "_set_iops.csv" #Create file for Host Export

foreach($esx in $esxHosts)

{

  Write-Host $esx #Display host Name

  $report += $esx.name

  ### $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(0,$null,$_.Device,1,"iops",$null)|Out-Null

    ###Display IOPS

    $report += $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get($_.device) |

        Add-Member -Name Host -Value $esx.Name -MemberType NoteProperty -PassThru

  }

  ###Change the default PSP

  $esxcli.storage.nmp.satp.set($null,”VMW_PSP_RR”,”VMW_SATP_SYMM”)

}

$report | Select Host,Device,ByteLimit,IOOperationLimit,LimitType,UseActiveUnoptimizedPaths |

Export-csv $csvfile -NoTypeInformation

#Disconnect from VirtualCenter

Disconnect-VIServer $VC -Confirm:$false | Out-Null

0 Kudos
weaverj
Contributor
Contributor
Jump to solution

Is there a way to set the IOPS=1 as the default with the policy or do we need to keep setting that as we add new storage?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

0 Kudos
weaverj
Contributor
Contributor
Jump to solution

I was hoping to set it in the script above (line 26) to do everything at once.  I believe I can change line 25 to:

$esxcli.storage.nmp.satp.rule.add($null,$null,"EMC Custom SYMM Rule",$null,$null,$null,"SYMMETRIX",$null,"VMW_PSP_RR","iops=1","VMW_SATP_SYMM",$null,$null,"EMC")

0 Kudos