PowerShell script exchange
Post Reply
mactex
Novice
Posts: 3
Liked: never
Joined: Sep 19, 2016 6:19 pm
Full Name: Matt McCarthy
Contact:

Job Name Followed by VM Count

Post by mactex »

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:

Code: Select all

Get-VBRJob | Select-Object name | Sort-Object

Code: Select all

Get-VBRJobObject -Job Jobtitle | Measure-Object | select -property count
Is it even possible to pipe the correct object from Get-VBRJob to Get-VBRObject? I'm guessing there is a better way to achieve this.
tdewin
Veeam Software
Posts: 1775
Liked: 646 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: Job Name Followed by VM Count

Post by tdewin » 1 person likes this post

This is pretty easy. The trick is to keep job object in place and not select the name directly

Code: Select all

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
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Job Name Followed by VM Count

Post by veremin »

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.

Thanks.
mactex
Novice
Posts: 3
Liked: never
Joined: Sep 19, 2016 6:19 pm
Full Name: Matt McCarthy
Contact:

Re: Job Name Followed by VM Count

Post by mactex »

Appreciate the help guys. I will give it a shot next week and report back; as I am out for the holidays. Happy holidays!
mactex
Novice
Posts: 3
Liked: never
Joined: Sep 19, 2016 6:19 pm
Full Name: Matt McCarthy
Contact:

Re: Job Name Followed by VM Count

Post by mactex »

Update: this works. Thanks again for the help!
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Job Name Followed by VM Count

Post by veremin » 1 person likes this post

You're welcome. Should other help be needed, don't hesitate to let us know. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests