#set the input options here as -vc and -cluster param([string]$vc = "vc", [string]$cluster = "cluster") #check to make sure we have both if (($vc -eq "vc") -or ($cluster -eq "cluster")) { write-host `n "Rescan-Storage rescans all HBAs, then goes back and rescans VMFS for all hosts in a specific cluster" `n Write-host `n "Required parameters are vc and cluster" `n `n "Example: `"Rescan-Storage -vc drtapw0015001 -cluster drtcrl0011101`"" `n break } #création du fichier $file = new-item "c:\Test\temptest.txt" -force -itemType File $file3 = new-item "c:\Test\res.txt" -force -itemType File #credential initialisation Add-PSSnapIn VMware.VimAutomation.Core $creds = Get-VICredentialStoreItem -file "C:\jonpol\credfile.xml" #connect to VC Connect-viserver -Server $creds.Host -User $creds.User -Password $creds.Password #get a list of physical servers in a specific cluster $servers = get-vmhost -location $cluster |sort name #command-line for scan all HBAs and VMFS $servers > $file $file2 = select-string -Path c:\Test\temptest.txt -Pattern '\d\d.\d\d.\d\d.\d\d\d' -AllMatches | % { $_.Matches } | % { $_.Value } function Convert-File { param($serv, $maxjobs = 6) $argument = @($serv) $running = @(Get-Job | ? {$_.State -eq 'Running'}) while ($running.Count -gt $maxJobs) { $done = Get-Job | Wait-Job -Any $running = @(Get-Job | ? {$_.State -eq 'Running'}) } start-job -scriptblock { Add-PSSnapIn VMware.VimAutomation.Core $creds = Get-VICredentialStoreItem -file "C:\jonpol\credfile.xml" Connect-viserver -Server $creds.Host -User $creds.User -Password $creds.Password Get-VMHostStorage -VMHost $args[0] -RescanAllHba -RescanVmfs } -ArgumentList $argument } foreach($hosts in $file2) { Convert-File $hosts } Get-Job | Wait-Job $out = Get-Job | Receive-Job echo $out #done, lets disconnect Disconnect-VIServer -confirm:$false