Job Name Followed by VM Count

PowerShell script exchange

Job Name Followed by VM Count

Veeam Logoby mactex » Wed Dec 21, 2016 9:53 pm

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.
mactex
Novice
 
Posts: 3
Liked: never
Joined: Mon Sep 19, 2016 6:19 pm
Full Name: Matt McCarthy

Re: Job Name Followed by VM Count

Veeam Logoby tdewin » Thu Dec 22, 2016 11:45 am 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
tdewin
Veeam Software
 
Posts: 1106
Liked: 389 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin

Re: Job Name Followed by VM Count

Veeam Logoby v.Eremin » Thu Dec 22, 2016 1:10 pm

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.
v.Eremin
Veeam Software
 
Posts: 13701
Liked: 1020 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Job Name Followed by VM Count

Veeam Logoby mactex » Thu Dec 22, 2016 11:22 pm

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: Mon Sep 19, 2016 6:19 pm
Full Name: Matt McCarthy

Re: Job Name Followed by VM Count

Veeam Logoby mactex » Tue Dec 27, 2016 2:29 pm

Update: this works. Thanks again for the help!
mactex
Novice
 
Posts: 3
Liked: never
Joined: Mon Sep 19, 2016 6:19 pm
Full Name: Matt McCarthy

Re: Job Name Followed by VM Count

Veeam Logoby v.Eremin » Wed Jan 04, 2017 11:51 am 1 person likes this post

You're welcome. Should other help be needed, don't hesitate to let us know. Thanks.
v.Eremin
Veeam Software
 
Posts: 13701
Liked: 1020 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 1 guest