Hi,
I am using a script to get multipath policy for the hosts. What i just need is a way for it to send me the report once it is completed. The catch is it should report only about those datastores/hosts which are not compliant.
Example: (If we are checking for host which have a path policy set as round robin the report should have all those hosts which are againt this rule -fixed/mru)
$Hosts = Get-Cluster cluster-name | Get-VMHost| Sort Name
ForEach ($VMHost in $Hosts) {
$ScsiLunsInfo = $VMHost | Get-ScsiLun -LunType disk
ForEach ($ScsiLun in $ScsiLunsInfo) {
$PathPolicy = (Get-ScsiLun -CanonicalName $ScsiLun -VmHost $VMHost).MultipathPolicy
#The logic is required here to display all those hosts which have a path policy of fixed/mru. The CSV file format should have something like "PathPolicy
# of $ScsiLun on $VMHost is $PathPolicy"
if ($PathPolicy -ne "RoundRobin") {
export-csv "C:\somefile.csv"
}}}
Thx,
A
That's the extra code I meant in my note in the pervious post.
One way of fixing this could be something like this
$Report = @() $esx = Get-Cluster MyCluster | Get-VMHost| Sort Name
ForEach ($VMHost in $esx) { $record = Get-ScsiLun -VmHost $VMHost -LunType disk |
where {$_.MultiPathPolicy -ne "RoundRobin"} |
select @{N="VMHost";E={$VMHost.Name}},CanonicalName,MultiPathPolicy
if($record){ $Report += $record
} } if($Report){ $Report | Export-Csv "C:\somefile.csv" -NoTypeInformation -UseCulture
}
In this case there will be no CSV file created when all of the LUNs have RoundRobin
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this.
With the Where-clause you can filter out the objects that you want, then collect them in an array and finally export the array to a CSV file.
$Report = @() $esx = Get-Cluster MyCLuster | Get-VMHost| Sort Name
ForEach ($VMHost in $esx) { $Report += Get-ScsiLun -VmHost $VMHost -LunType disk |
where {$_.MultiPathPolicy -ne "RoundRobin"} |
select @{N="VMHost";E={$VMHost.Name}},CanonicalName,MultiPathPolicy
} $Report | Export-Csv "C:\somefile.csv" -NoTypeInformation -UseCulture
Note that the script will need some extra code if you should stumble upon the case where all your LUNs are using RoundRobin
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc for the prompt reply. This is what I was looking for. Only one thing which I want to point is if we run with the condition (check multipath policy fixed) and if in case all the hosts meet the required condition the script returns the following:
"Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null" and that too in large numbers.
Is there a way to suppress it?
Thx,
A
That's the extra code I meant in my note in the pervious post.
One way of fixing this could be something like this
$Report = @() $esx = Get-Cluster MyCluster | Get-VMHost| Sort Name
ForEach ($VMHost in $esx) { $record = Get-ScsiLun -VmHost $VMHost -LunType disk |
where {$_.MultiPathPolicy -ne "RoundRobin"} |
select @{N="VMHost";E={$VMHost.Name}},CanonicalName,MultiPathPolicy
if($record){ $Report += $record
} } if($Report){ $Report | Export-Csv "C:\somefile.csv" -NoTypeInformation -UseCulture
}
In this case there will be no CSV file created when all of the LUNs have RoundRobin
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Awesome...thanks!
Hi LucD,
I want to know which datastore have mutlipathing in a cluster i.e in my case on 1 hba the device is visible and not other hba. So using a script I want to search such luns which are only mapped to hba 1 and not hba 2.
So please help me on this.
Regards,
Babu Raju.
Vizag.
Hi Team,
Please Anybody help me on this.
Regards,
Baburaju.
LucD,
Does the script require any changes for VMware 6.5 ? I did try, but no output generates.
thanks
vmk
No, no change required for 6.5.
Do you have an empty CSV file?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Actually, it not generating any file at all. Blank output in screen without any error.
Thanks
vmk
What does this return?
Get-Cluster -PipelineVariable cluster | Get-VMHost -PipelineVariable esx |
Get-ScsiLun -LunType disk |
select @{N='Cluster';E={$cluster.Name}},@{N="VMHost";E={$esx.Name}},
CanonicalName,MultiPathPolicy
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, it shows output below.
Cluster VMHost CanonicalName MultipathPolicy
------- ------ ------------- ---------------
Winds_LNG_Cluster wa-esxl2.espsg.local mpx.vmhba0:C0:T64:L0 Fixed
Winds_LNG_Cluster wa-esxl2.espsg.local naa.6000144000000010603d786248fb5f2c RoundRobin
Winds_LNG_Cluster wa-esxl2.espsg.local naa.600014400000001060282d9c8ac23446 RoundRobin
Winds_LNG_Cluster wa-esxl2.espsg.local naa.600508b1001c123eeeb6ffb0c5dddc12 Fixed
Winds_LNG_Cluster wa-esxl1.esosg.local mpx.vmhba0:C0:T64:L0 Fixed
Winds_LNG_Cluster wa-esxlg1.espsg.local naa.600508b1001cfe2c7b6bda60d0ff2462 Fixed
thanks
vmk
Then you can just pipe the result to a CSV
Get-Cluster -PipelineVariable cluster | Get-VMHost -PipelineVariable esx |
Get-ScsiLun -LunType disk |
select @{N='Cluster';E={$cluster.Name}},@{N="VMHost";E={$esx.Name}},
CanonicalName,MultiPathPolicy |
Export-Csv -Path .\report.csv -UseCulture -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference