bmorrison4
Contributor
Contributor

PowerCLI RDM Report with IOPS Count

Jump to solution

I have been banging my head trying to get the IOPS field added to our RDM report.

I'm wanting the column to show the -CommandsToSwitchPath but the column is empty everytime I try.

 

Here is what I have and I'll take any suggestions at this point!

Get-VM | Sort-Object | Get-HardDisk | Where-Object {$_.DiskType -like “Raw*”} |
Select @{N=”VMName”;E={$_.Parent}},Name,DiskType,@{N=”LUN_ID”;E={$_.ScsiCanonicalName}},
@{N='SCSIid';E={$th = $_
$ctrl = $th.Parent.Extensiondata.Config.Hardware.Device | Where {$_.Key -eq $th.ExtensionData.ControllerKey}
"$($ctrl.BusNumber):$($_.ExtensionData.UnitNumber)"}},Filename,CapacityGB,@{N="IOPS";E={Get-ScsiLun -LunType disk | Select-Object CommandsToSwitchPath}} |
Export-Csv "C:\RDM_IOPS.csv" -NoTypeInformation

 

The problem is this part and I don't think I'm doing this right:::

@{N="IOPS";E={Get-ScsiLun -LunType disk | Select-Object CommandsToSwitchPath}}

0 Kudos
2 Solutions

Accepted Solutions
LucD
Leadership
Leadership

That seems to indicate you have shared RDM, connected to multiple VMs.

Try this variation, it will show all VMs connected to a shared RDM LUN

 

$getCluster = Get-Cluster
$getESXis = $getCluster | Get-VMHost
$printluns = @()

# Get all RDM luns and store with VM name
$lunTab = @{}
Get-VM -Location $getCluster -PipelineVariable vm |
Get-HardDisk | Where-Object { $_.DiskType -like “Raw*” } |
ForEach-Object -Process {
    if($lunTab.ContainsKey($_.ScsiCanonicalName)) {
        $lunTab[$_.ScsiCanonicalName] = $lunTab[$_.ScsiCanonicalName], $vm.Name -join '|'
    }
    else {
        $lunTab.Add($_.ScsiCanonicalName,$vm.Name)
    }
}

foreach ($getESXi in $getESXis) {
  $printluns += Get-VMHost $getESXi | Get-ScsiLun -LunType disk |
    Select-Object VMHost, CanonicalName, MultipathPolicy, CommandsToSwitchPath,
      @{N='VM';E={$lunTab[$_.CanonicalName]}}
}

$printluns | Export-Csv "$FileCSV1" -NoTypeInformation

 




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

View solution in original post

0 Kudos
LucD
Leadership
Leadership

Does this where-clause do the trick?

$getCluster = Get-Cluster
$getESXis = $getCluster | Get-VMHost
$printluns = @()

# Get all RDM luns and store with VM name
$lunTab = @{}
Get-VM -Location $getCluster -PipelineVariable vm |
Get-HardDisk | Where-Object { $_.DiskType -like “Raw*” } |
ForEach-Object -Process {
    if($lunTab.ContainsKey($_.ScsiCanonicalName)) {
        $lunTab[$_.ScsiCanonicalName] = $lunTab[$_.ScsiCanonicalName], $vm.Name -join '|'
    }
    else {
        $lunTab.Add($_.ScsiCanonicalName,$vm.Name)
    }
}

foreach ($getESXi in $getESXis) {
  $printluns += Get-VMHost $getESXi | Get-ScsiLun -LunType disk |
    where{$_.CommandsToSwitchPath -ne 200} |
    Select-Object VMHost, CanonicalName, MultipathPolicy, CommandsToSwitchPath,
      @{N='VM';E={$lunTab[$_.CanonicalName]}}
}

$printluns | Export-Csv "$FileCSV1" -NoTypeInformation


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

View solution in original post

0 Kudos
13 Replies
LucD
Leadership
Leadership

Try with

        @{N="IOPS";E={Get-ScsiLun -CanonicalName $_.ScsiCanonicalName -LunType disk | Select-Object CommandsToSwitchPath}} |


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

0 Kudos
bmorrison4
Contributor
Contributor

I tried your suggestion and it's still blank on the IOPS column.

 

Get-VM | Sort-Object | Get-HardDisk | Where-Object {$_.DiskType -like “Raw*”} |
Select @{N=”VMName”;E={$_.Parent}},Name,DiskType,@{N=”LUN_ID”;E={$_.ScsiCanonicalName}},
@{N='SCSIid';E={$th = $_
$ctrl = $th.Parent.Extensiondata.Config.Hardware.Device | Where {$_.Key -eq $th.ExtensionData.ControllerKey}
"$($ctrl.BusNumber):$($_.ExtensionData.UnitNumber)"}},Filename,CapacityGB,@{N="IOPS";E={Get-ScsiLun -CanonicalName $_.ScsiCanonicalName -LunType disk | Select-Object CommandsToSwitchPath}} |
Export-Csv "C:\RDM_IOPS.csv" -NoTypeInformation

0 Kudos
LucD
Leadership
Leadership

And with

  @{N="IOPS";E={Get-ScsiLun -CanonicalName $_.ScsiCanonicalName -LunType disk | Select-Object -ExpandProperty CommandsToSwitchPath}} |

You are sure there is something in the CommansToSwitchPath property?


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

0 Kudos
bmorrison4
Contributor
Contributor

Yea still blank on the IOPS column. I have this other script below that shows the CommandsToSwitchPath column but this one does not have the VM name like the RDM script that I'm trying to add the IOPS (CommandsToSwitchPath) column.

 

$getCluster = Get-Cluster
$getESXis = $getCluster | Get-VMHost
$printluns=@()

foreach ($getESXi in $getESXis)
{
$getLUNsforESXi = Get-VMHost $getESXi | Get-ScsiLun -LunType disk | Select VMHost, CanonicalName, MultipathPolicy, CommandsToSwitchPath
$printluns = $printluns + $getLUNsforESXi
}

$printluns | Export-csv "$FileCSV1" -NoTypeInformation

 

Would there be an easier way to add the VMName column to this script instead?

0 Kudos
LucD
Leadership
Leadership

You could try something like this

$getCluster = Get-Cluster
$getESXis = $getCluster | Get-VMHost
$printluns = @()

# Get all RDM luns and store with VM name
$lunTab = @{}
Get-VM -Location $getCluster -PipelineVariable vm |
Get-HardDisk | Where-Object { $_.DiskType -like “Raw*” } |
ForEach-Object -Process {
  $lunTab.Add($_.ScsiCanonicalName,$vm.Name)
}

foreach ($getESXi in $getESXis) {
  $printluns += Get-VMHost $getESXi | Get-ScsiLun -LunType disk |
    Select-Object VMHost, CanonicalName, MultipathPolicy, CommandsToSwitchPath,
      @{N='VM';E={$lunTab[$_.CanonicalName]}}
}

$printluns | Export-Csv "$FileCSV1" -NoTypeInformation


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot

LucD,

I am getting the below error, while I execute the above script

ganapa2000_0-1661345779409.png

 

0 Kudos
LucD
Leadership
Leadership

That seems to indicate you have shared RDM, connected to multiple VMs.

Try this variation, it will show all VMs connected to a shared RDM LUN

 

$getCluster = Get-Cluster
$getESXis = $getCluster | Get-VMHost
$printluns = @()

# Get all RDM luns and store with VM name
$lunTab = @{}
Get-VM -Location $getCluster -PipelineVariable vm |
Get-HardDisk | Where-Object { $_.DiskType -like “Raw*” } |
ForEach-Object -Process {
    if($lunTab.ContainsKey($_.ScsiCanonicalName)) {
        $lunTab[$_.ScsiCanonicalName] = $lunTab[$_.ScsiCanonicalName], $vm.Name -join '|'
    }
    else {
        $lunTab.Add($_.ScsiCanonicalName,$vm.Name)
    }
}

foreach ($getESXi in $getESXis) {
  $printluns += Get-VMHost $getESXi | Get-ScsiLun -LunType disk |
    Select-Object VMHost, CanonicalName, MultipathPolicy, CommandsToSwitchPath,
      @{N='VM';E={$lunTab[$_.CanonicalName]}}
}

$printluns | Export-Csv "$FileCSV1" -NoTypeInformation

 




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

0 Kudos
ganapa2000
Hot Shot
Hot Shot

Hi LucD,

I was getting the below error

At D:\myreports\RDM_IOPS_Info\RDM_IOPS_Info.ps1:11 char:28
+ if($lunTab.ContainsKey(ScsiCanonicalName))
+ ~
Missing ')' in method call.
At D:\myreports\RDM_IOPS_Info\RDM_IOPS_Info.ps1:11 char:28
+ if($lunTab.ContainsKey(ScsiCanonicalName))
+ ~~~~~~~~~~~~~~~~~
Unexpected token 'ScsiCanonicalName' in expression or statement.
At D:\myreports\RDM_IOPS_Info\RDM_IOPS_Info.ps1:11 char:28
+ if($lunTab.ContainsKey(ScsiCanonicalName))
+ ~~~~~~~~~~~~~~~~~
Missing closing ')' after expression in 'if' statement.
At D:\myreports\RDM_IOPS_Info\RDM_IOPS_Info.ps1:10 char:25
+ ForEach-Object -Process {
+ ~
Missing closing '}' in statement block or type definition.
At D:\myreports\RDM_IOPS_Info\RDM_IOPS_Info.ps1:11 char:45
+ if($lunTab.ContainsKey(ScsiCanonicalName))
+ ~
Unexpected token ')' in expression or statement.
At D:\myreports\RDM_IOPS_Info\RDM_IOPS_Info.ps1:11 char:46
+ if($lunTab.ContainsKey(ScsiCanonicalName))
+ ~
Unexpected token ')' in expression or statement.
At D:\myreports\RDM_IOPS_Info\RDM_IOPS_Info.ps1:14 char:7
+ } else {
+ ~~~~
Unexpected token 'else' in expression or statement.
At D:\myreports\RDM_IOPS_Info\RDM_IOPS_Info.ps1:17 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

 

I changed the below line

if($lunTab.ContainsKey(ScsiCanonicalName)) {

To

if($lunTab.ContainsKey($_.ScsiCanonicalName)) {

 

Now, I am able to get the output but , CommandsToSwitchPath column shows blank

0 Kudos
LucD
Leadership
Leadership

I also updated the typo in my code above.

No clue why that returns a blank in case of an RDM.


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

0 Kudos
bmorrison4
Contributor
Contributor

This script is awesome and is exactly what I was looking for! I hope others find this useful for their environments because this helps us report IOPS count for all of our RDM's. Thank you LucD!

0 Kudos
bmorrison4
Contributor
Contributor

Hi Luc, is there any way to make this report so it will only report if the IOPS count does NOT equal 200? I've been racking my brain around this for days and can't figure out how.

The reason for this report is because we use IOPS 200 based on VMware KB (Adjusting Round Robin IOPS limit from default 1000 to 1 (2069356) (vmware.com)) and we would like this report to let us know if anything is not set to 200.

0 Kudos
LucD
Leadership
Leadership

Does this where-clause do the trick?

$getCluster = Get-Cluster
$getESXis = $getCluster | Get-VMHost
$printluns = @()

# Get all RDM luns and store with VM name
$lunTab = @{}
Get-VM -Location $getCluster -PipelineVariable vm |
Get-HardDisk | Where-Object { $_.DiskType -like “Raw*” } |
ForEach-Object -Process {
    if($lunTab.ContainsKey($_.ScsiCanonicalName)) {
        $lunTab[$_.ScsiCanonicalName] = $lunTab[$_.ScsiCanonicalName], $vm.Name -join '|'
    }
    else {
        $lunTab.Add($_.ScsiCanonicalName,$vm.Name)
    }
}

foreach ($getESXi in $getESXis) {
  $printluns += Get-VMHost $getESXi | Get-ScsiLun -LunType disk |
    where{$_.CommandsToSwitchPath -ne 200} |
    Select-Object VMHost, CanonicalName, MultipathPolicy, CommandsToSwitchPath,
      @{N='VM';E={$lunTab[$_.CanonicalName]}}
}

$printluns | Export-Csv "$FileCSV1" -NoTypeInformation


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

0 Kudos
bmorrison4
Contributor
Contributor

Outstanding! This was driving me crazy, thank you so much, it works great!

0 Kudos