I'm trying to get an output of all enabled job names with VM counts for each. I can get one or the other but having a difficult time combining these two:
asnp veeampssnapin
$alljobs = get-vbrjob | Sort-Object -Property Name
#Scheduler is enabled or not
$filteredjobs = $alljobs | Where-Object { $_.CanRunByScheduler() }
foreach ($job in $filteredjobs) {
$objects = @(Get-VBRJobObject -Job $job)
write-host ("{0} ({1})" -f $job.Name,$objects.Count)
}
The @() forces powershell to think about the returned pipeline as an array even if it returns one object. You can then just use the count property of the array
However, be aware that said counter returns number of source objects, therefore, if containers such as VM folders, Resource Pools and similar are selected as job source, counter will return number of containers (1 in most cases) and not number of VMs present inside those entities.
Let us know whether this is the case, so that we can modify script accordingly.