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!
I corrected this in the script in my first post. Now it should work and only retrieve information about the two clusters.
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
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
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
.
adding this to my arsenal, thanks RvdNieuwendijk!
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
Add $_ after the "get-cluster" and before the pipe '|'
vExpert
VMware Communities Moderator
-KjB
I corrected this in the script in my first post. Now it should work and only retrieve information about the two clusters.
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
Thank you, Gentlemen!
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
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
