- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In method 1 you can avoid that the script stops when the VC is in trouble by adding the -ErrorAction SilentlyContinue parameter on the Connect-VIServer.
You will have to test yourself if the connected worked or not, and depending on the result retrieve the data or not.
Something like this
$vcName = "MyVC"
$vc = Connect-VIServer -Server $vcName -ErrorAction SilentlyContinue
if($vc.IsConnected){ # Collect the date } else{ # Connection to VC failed, display error message Write-Error "Connection to $($vcName) failed !"
}
Method 2 can indeed take a considerable time in a larger environment.
Here you can optimise the speed by using the Get-View cmdlet and by using the Property parameter.
Like this
Get-View -ViewType HostSystem -Property "Name","VM"
and limit the properties to only the ones you need in the script.
Method 4 would my personal choice, you run/schedule the inventory script from a single station and you use a PowerShell feature to "multi-thread".
But be aware that the Start-Job in combination with a PowerCLI script needs some specific coding in your script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference