VMware Cloud Community
bmorrison4
Contributor
Contributor
Jump to solution

PowerCLI RDM Report with IOPS Count

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}}

Reply
0 Kudos
2 Solutions

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
13 Replies
LucD
Leadership
Leadership
Jump to solution

Try with

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


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

Reply
0 Kudos
bmorrison4
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
bmorrison4
Contributor
Contributor
Jump to solution

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?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

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

ganapa2000_0-1661345779409.png

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
bmorrison4
Contributor
Contributor
Jump to solution

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!

Reply
0 Kudos
bmorrison4
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
bmorrison4
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos