Hello Everyone,
I am looking for a solution where I want to fetch details from Multiple Virtual centers.
If I want to get VM information from multiple VC with the normal foreach VC loop it takes long time to complete information.
There is a way (Start-job) to run function or scriptblock in parallel process.
But issue is how and where i put my all VC list to first connect to the VC and then fetch the information.
Here is my code if you can help me to run this with parallel process to save time
#region GET-VMInventory Function
function Get-VMInfo {
[CmdletBinding()]
param (
[Parameter(Mandatory=$True)]
[string[]]$VC
)
#region Plugin
if(-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue))
{
Add-PSSnapin VMware.VimAutomation.Core
}
#endregion
Connect-Viserver $vc
$props = @()
$VMs = Get-VM | select -First 2
$i = 0
$E = 0
$count = $vms.Count
$E = $count
Write-Host ""
Write-Host "-----------------------------"
Write-Host "Total Count of VMs - $count"
Write-Host "-----------------------------"
foreach ($vm in $VMs) {
# Get Start Time
$startVMCheck = (Get-Date)
$i++
Write-Progress -activity “Checking for VM: ($i of $E) >> $VM" -perc (($i / $E)*100)
$vCenterServer = ($vm).ExtensionData.Client.ServiceUrl.Split('/')[2]#.trimend(":443")
$MacAddress = ($vm | Get-NetworkAdapter).MacAddress -join ", `n"
$Results = New-Object Object
$Results | Add-Member -Type NoteProperty -Name 'VCName' -Value $vCenterServer
$Results | Add-Member -Type NoteProperty -Name 'VMName' -Value $vm.Name
$Results | Add-Member -Type NoteProperty -Name 'IP Address'-value $vm.Guest.IPAddress[0] #$VM.ExtensionData.Summary.Guest.IpAddress
$Results | Add-Member -Type NoteProperty -Name 'MacAdress' -value $MacAddress
$Results | Add-Member -Type NoteProperty -Name 'PowerState' -value $vm.PowerState
$props += $Results
# Get End Time
$endVMCheck = (Get-Date)
Write-Host "VM - $VM Checked in Time: '$(($EndVMCheck-$StartVMCheck).TotalMinutes)' Minutes "
}
Write-Output $props
Disconnect-VIServer $VC -Confirm:$False
}
#endregion
Get-VMInfo -vc "VC01"