PowerShell script exchange
Post Reply
serverbu
Enthusiast
Posts: 38
Liked: 4 times
Joined: Feb 19, 2014 4:30 pm
Contact:

Q: Is there a cmdlet to get jobs a vm is in

Post by serverbu »

Hello,

as the title implicates, we want to get all the jobs a specific vm is in.

'Till now we do this with a Get-VBRJob to get names of all jobs and pass this list, jobname by jobname through a loop, to Get-VBRJobObject and compare all vm-names in the result list with the one we are looking for, to see if the specific vm is in that job. If so the script returns the jobs name and Get-VBRJobObject is called with the next job name from Get-VBRJob.

Is there a more direct approach through a cmdlet? We've looked for something like '

Code: Select all

Get-VMsJobNames -name "VM Name"
' or '

Code: Select all

Find-JobsOfVM -name "VM Name"
' or likewise cmdlets but didn't found any cmdlet in help or documentation that implicateted such usage through its name.

Best regards
veremin
Product Manager
Posts: 20261
Liked: 2249 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Q: Is there a cmdlet to get jobs a vm is in

Post by veremin »

There is no need in additional commandlet, as everything can be done via the following one-liner:

Code: Select all

Get-VBRJob | ?{$_.GetObjectsInJob().name -eq "Name of VM"} | select name
Thanks.
serverbu
Enthusiast
Posts: 38
Liked: 4 times
Joined: Feb 19, 2014 4:30 pm
Contact:

Re: Q: Is there a cmdlet to get jobs a vm is in

Post by serverbu »

Code: Select all

Get-VBRJob | ?{$_.GetObjectsInJob().name -eq "Name of VM"} | select name
What exactly is returned by this?
I tried this with each and every vm name we have in any job, but it didn't seem to return anything at all.
veremin
Product Manager
Posts: 20261
Liked: 2249 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Q: Is there a cmdlet to get jobs a vm is in

Post by veremin »

The provided script returns names of jobs that have VM with the defined name as their source. Are you using individual VMs or containers (folders, resource pools, hosts, etc.) as jobs' source? What product version you're using? Thanks.
serverbu
Enthusiast
Posts: 38
Liked: 4 times
Joined: Feb 19, 2014 4:30 pm
Contact:

Re: Q: Is there a cmdlet to get jobs a vm is in

Post by serverbu »

The Problem was caused by a misstype in the script. After I corrected my misstype I got the expected result.

Thanks for your help.
veremin
Product Manager
Posts: 20261
Liked: 2249 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Q: Is there a cmdlet to get jobs a vm is in

Post by veremin »

Glad to hear my input was helpful. Don't hesitate to ask, should other assistance be needed.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests