VMware Cloud Community
Troy_Clavell
Immortal
Immortal
Jump to solution

Get Multi-Path Information

I found this code. Is there a way I can get the results into a excel document instead of just the screen?

Get-VMHost | %{$_.Name; $_ | Get-ScsiLun | Select CanonicalName, MultiPathPolicy}

And even better, since I will be connecting to a vCenter4 instance, I really only need information from two of our clusters. The Cluster Names are ProductionCluster8 and ProductionCluster9

Thank you!

Reply
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

I corrected this in the script in my first post. Now it should work and only retrieve information about the two clusters.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

Reply
0 Kudos
11 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Troy,

of course what you asked is possible in PowerCLI ;-). I have changed your code a little bit so that it gives the hostname on everly line in the spreadsheet. The script returns a .csv file which you can import in Excel.

"ProductionCluster8","ProductionCluster9" | ForEach-Object {
  Get-Cluster $_ | Get-VMHost | ForEach-Object {
    $VMHost = $_
    $VMHost | Get-ScsiLun | ForEach-Object {
      $Report = "" | Select-Object -Property VMHost,CanonicalName,MultiPathPolicy
      $Report.VMHost = $VMHost.Name
      $Report.CanonicalName = $_.CanonicalName
      $Report.MultiPathPolicy = $_.MultiPathPolicy
      $Report
    }
  }
} | Export-Csv -NoTypeInformation -Path c:\temp\Multipathinformation.csv

Regards, Robert

Message was edited by: RvdNieuwendijk

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
esarakaitis
Enthusiast
Enthusiast
Jump to solution

try this version, its much much faster:

$initalTime = Get-Date
$filepath = "C:\tmp"
$filename = "LunPathState"
$date = Get-Date ($initalTime) -uformat %Y%m%d
$time = Get-Date ($initalTime) -uformat %H%M

Write-Host "$(Get-Date ($initalTime) -uformat %H:%M:%S) - Starting"

$AllHosts = Get-VMHost | Sort Name

$reportLunPathState = @()

Write-Host "$(Get-Date -uformat %H:%M:%S) - $($AllHosts.length) hosts acquired"

$i = 0

ForEach ($VMHost in $AllHosts) {
    $i++
    Write-Host "$(Get-Date -uformat %H:%M:%S) - $($i) of $($AllHosts.length) - $($VMHost)"
    $VMHostScsiLuns = $VMHost | Get-ScsiLun -LunType disk
    ForEach ($VMHostScsiLun in $VMHostScsiLuns) {
        $VMHostScsiLunPaths = $VMHostScsiLun | Get-ScsiLunPath
        $reportLunPathState += ($VMHostScsiLunPaths | Measure-Object) | Select @{N="Hostname"; E={$VMHost.Name}}, @{N="Number of Paths"; E={$_.Count}}, Name, State
        $reportLunPathState += $VMHostScsiLunPaths | Select @{N="Hostname"; E={$VMHost.Name}}, "Number of Paths", Name, State
    }
}

$conclusionTime = Get-Date
Write-Host "$(Get-Date ($conclusionTime) -uformat %H:%M:%S) - Finished"
$totalTime = New-TimeSpan $initalTime $conclusionTime
Write-Host "$($totalTime.Hours):$($totalTime.Minutes):$($totalTime.Seconds) - Total Time"

$reportLunPathState | Out-GridView

$reportLunPathState | Export-Csv $filepath\$date$time"-"$filename".csv" -NoType

http://www.vmwareadmins.com

http://www.vmwarescripting.com

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

I wonder why you think that your script is faster than mine? I ran both scripts in the same environment with two clusters and no hosts outside the clusters. Here are the results from the Measure-Command cmdlet:

My script:   TotalSeconds      :  54,6660997
Your script: TotalSeconds      : 267,284474

I think that makes my script almost five times faster Smiley Wink.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
monderick
Enthusiast
Enthusiast
Jump to solution

adding this to my arsenal, thanks RvdNieuwendijk!

Reply
0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

Hey Robert, Script works great. However unless I am running incorrectly, it's pulling information from all 4 of my clusters. Not a bad thing, but is there a way just to tell it to pull from ProductionCluster8 and 9

all I did at to the script was add in at the beginning

connect-viserver -Server

and at the end

Disconnect-VIServer -Confirm:$false

Reply
0 Kudos
kjb007
Immortal
Immortal
Jump to solution

Add $_ after the "get-cluster" and before the pipe '|'

vExpert

VMware Communities Moderator

-KjB

vExpert/VCP/VCAP vmwise.com / @vmwise -KjB
RvdNieuwendijk
Leadership
Leadership
Jump to solution

I corrected this in the script in my first post. Now it should work and only retrieve information about the two clusters.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
monderick
Enthusiast
Enthusiast
Jump to solution

i noticed the same thing (grabbing data from all clusters) and made a slight modification:

Get-Cluster "cluster1","cluster2" | Get-VMHost | ForEach-Object {

$VMHost = $_

$VMHost | Get-ScsiLun | ForEach-Object {

$Report = "" | Select-Object -Property VMHost,CanonicalName,MultiPathPolicy

$Report.VMHost = $VMHost.Name

$Report.CanonicalName = $_.CanonicalName

$Report.MultiPathPolicy = $_.MultiPathPolicy

$Report

}

} | Export-Csv -NoTypeInformation -Path c:\tmp\Multipathinformation.csv

Reply
0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

Thank you, Gentlemen!

Reply
0 Kudos
Nicodemus555
Contributor
Contributor
Jump to solution

Coming late to this party but...

When I run this script it returns the " naa. " CanonicalName results:

naa.60060e8005c003000000c00300004300 RoundRobin

naa.60060e8005c003000000c00300004301 RoundRobin

naa.60060e8005c003000000c00300004302 RoundRobin

naa.60060e8005c003000000c00300004303 Fixed

naa.60060e8005c003000000c00300004304 Fixed

But what I am after ( I think ) is to know if my multi-pathing is working or configured correctly ( after SAN team maintanence ) and would like to see results more like the 'Runtime Name:

vmhba1:C0:T0:Lx

vmhba1:C0:T1:Lx

vmhba2:C0:T0:Lx

vmhba2:C0:T1:lX

How can I change this script to specific HBAs 1 & 2 (my Fibre channels) and to return the vmhba type results..?

Appreciate any help, - Nicodemus

Reply
0 Kudos
Nicodemus555
Contributor
Contributor
Jump to solution

FWIW.. found an answer at:

http://www.lucd.info/2010/10/17/runtime-name-via-extensiondata-and-new-viproperty/

"One of the demos we did in our VMworld 2010 US and Europe sessions, showed the use of the new Extensiondata property and of the new New-VIProperty cmdlet. Both features were introduced with PowerCLI 4.1. In my PowerCLI 4.1 brings the New-VIProperty cmdlet post I already showed the interesting possibilities this new cmdlet offers.

On my return from VMworld Europe there was a new thread in the PowerCLI Community that asked how one could get at the Runtime Name property as it is shown in the vSphere Client. The Get-ScsiLun and Get-ScsiLunPath cmdlets unfortunately do not return that property. So I guessed it was time to show once more the strength of the New-VIProperty cmdlet"

Although I am still not sure how to use it yet... - Nicodemus

Reply
0 Kudos