Greetings. I have this script that tells me the HBA device path status (Dead, Active). But, it takes forever to run on all my hosts since it does each host one at a time.
How can I get it to run on all the hosts concurrently?
Usage: Get-HBAPathStatus VMHosts*
Thanks!
function Get-HBAPathStatus($InputVMHost){
$vmhosts = Get-VMHost $InputVMHost | Sort Name
foreach($vmhost in $vmhosts) {
Write-Host "***** $vmhost *****"
Write-Host "Please wait...Checking Paths..."
$hbas = Get-VMHostHba -VMhost $vmhost
$pathStatus = $true
foreach($hba in $hbas) {
$scsiluns = Get-ScsiLun -Hba $hba
foreach($scsilun in $scsiluns) {
if($scsilun -ne $null) {
$paths = Get-ScsiLunPath -ScsiLun $scsilun
foreach($path in $paths) {
Write-Host -NoNewline "."
if($path.State -eq "Dead") {
$pathStatus = $false
}
}
}
}
}
if($pathStatus) {
Write-Host ""
Write-Host "$vmhost is ok" -ForegroundColor "Green"
}
else {
Write-Host ""
Write-Host "$vmhost has dead paths." -ForegroundColor "Red"
}
}
}
Don't forget to use the 32-bit version of PowerShell and PowerCLI with the Start-Job cmdlet.
The job will fail with 64-bit version.
See the Disable paths asynchronously thread for more info.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Rewrite your function so it only does one host.
Then use the powershell start-job command to run against each host in parallel.
Don't forget to use the 32-bit version of PowerShell and PowerCLI with the Start-Job cmdlet.
The job will fail with 64-bit version.
See the Disable paths asynchronously thread for more info.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks guys! I'm still pretty new to this and it'll take me a bit to figure out; but, I get the jist of what you're saying. I'll see if I can't re-work the function.
Thanks again!
Guys, so I finally got back to working on this... here's what I got so far & could use some help.
Have a servers.txt that contains the list of servers (one per line) that I want this to execute on.
Then I have the following script. It starts 4 different jobs, but they never complete. Any help? Thanks again!
$Job = {
param($vmhost)
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
$server = "nodcapts0607.no.trinity-health.org"
Connect-VIServer $server
$hbas = Get-VMHostHba -VMhost $vmhost
$pathStatus = $true
foreach($hba in $hbas) {
$scsiluns = Get-ScsiLun -Hba $hba
foreach($scsilun in $scsiluns) {
if($scsilun -ne $null) {
$paths = Get-ScsiLunPath -ScsiLun $scsilun
foreach($path in $paths) {
#Write-Host -NoNewline "."
if($path.State -eq "Dead") {
$pathStatus = $false
}
}
}
}
}
if($pathStatus) {
$objStatus = "$vmhost is ok"
$arrStatus += $objStatus
}
else {
$objStatus = "$vmhost has dead paths"
$arrStatus += $objStatus
}
$arrStatus > .\$vmhost-Results.txt
}
Get-Content .\servers.txt | Foreach-object {Start-Job -ScriptBlock $Job -ArgumentList $_ }
Change -ArgumentList $_ to -ArgumentList @($_)