Powershell to get list of VM's in a Veeam backup job

PowerShell script exchange

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby v.Eremin » Wed Mar 04, 2015 11:11 am

How do I output that query to the screen?

Just open a PS, and input the mentioned script line by line. The last line should output the VM objects to the screen.

I need but still only pulls the single VM jobs and not jobs with more than 1 VM.

So, the script doesn't list jobs containing more than one VM as source or it lists only the first VM for such jobs?
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby chris.childerhose » Wed Mar 04, 2015 3:08 pm

It does not list any job with more than 1 VM selected within it. If the job has only 1 VM selected it is listed for my column in the CSV file. Not sure why this is the case but if I cannot figure it out I will populate the spreadsheet for those jobs manually. Would have been nice to automate it.

I ran the lines you mentioned one at a time on a job with 3 VMs within it and the last line did not display anything. I then ran the same lines on a job with 1 VM and it showed the name of the VM.
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby v.Eremin » Wed Mar 04, 2015 3:14 pm

Hmm, interesting. Do those variables at least contain something or not?

Code: Select all
$Job = Get-VBRJob -name "Name of your backup job with multiple VMs"
$Job
$Objects = $Job | Get-VBRJobObject
$Objects


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby chris.childerhose » Wed Mar 04, 2015 3:42 pm

The first variable $Job contains something with either jobs - single or multiple VMs. The second variable $Objects does not contain anything for the multiple VM jobs but does for the single VM jobs. It is weird.
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby v.Eremin » Wed Mar 04, 2015 3:50 pm

Agree, absolutely strange behaviour as to me.

And VM objects don't get populated via PS regardless of used approach?

Code: Select all
$Job = Get-VBRJob -name "Name of your backup Job"
$Job.GetViOijs()

$Job.GetObjectsInJob()


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby chris.childerhose » Wed Mar 04, 2015 3:56 pm

v.Eremin wrote:Agree, absolutely strange behaviour as to me.

And VM objects don't get populated via PS regardless of used approach?

Code: Select all
$Job = Get-VBRJob -name "Name of your backup Job"
$Job.GetViOijs()

$Job.GetObjectsInJob()


Thanks.


When using these methods I can see all VMs in a multi-VM job. Both variables display the VMs.
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby v.Eremin » Wed Mar 04, 2015 4:31 pm

Ok, so what if you integrate this part into the referenced code?

Code: Select all
    foreach ($job in Get-VBRJob) {
       $jobOptions = New-Object PSObject
       
       $Objects = $Job.GetViOijs()
       
       $jobOptions | Add-Member -MemberType NoteProperty -Name "Name" -value $job.name
       $jobOptions | Add-Member -MemberType NoteProperty -Name "Objects" -value $Objects.name
}


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby chris.childerhose » Wed Mar 04, 2015 4:41 pm

v.Eremin wrote:Ok, so what if you integrate this part into the referenced code?

Code: Select all
    foreach ($job in Get-VBRJob) {
       $jobOptions = New-Object PSObject
       
       $Objects = $Job.GetViOijs()
       
       $jobOptions | Add-Member -MemberType NoteProperty -Name "Name" -value $job.name
       $jobOptions | Add-Member -MemberType NoteProperty -Name "Objects" -value $Objects.name
}


Thanks.


Nope that doesn't work and does not show even jobs with 1 VM in it. I then replace it with this and it shows my 1 VM jobs fine but not multiple VM jobs -

$Objects = Get-VBRJobObject $job

So I am stumped and going to manually populate my spreadsheets for now. Maybe this is a bug in the Powershell code?
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby tsightler » Wed Mar 04, 2015 5:24 pm

chris.childerhose wrote:I am running Powershell 2.0 - should it be updated to 3.0 for Veeam 8? Maybe there is something there but I cannot get the jobs with multiple VMs to spit them out in the CSV file. Grrrr :(

I really would suggest upgrading to the lastest Powershell as there are some very strange behaviors if you are running older versions including some of the things you are noting (object methods not returning values, etc).

I believe the primary issue you are having is that you are trying to create a string output, but you are adding array based objects to the list. You'll need some help to actually turn those objects into a simple comma separated string and then add that as a single string property. I'll try to get the script to run in my lab and see what's up as it looks like it would be "easy", but it the meantime I strongly suggest installing WMF 4.0 so that you can get the latest Powershell.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby v.Eremin » Wed Mar 04, 2015 5:27 pm

Maybe this is a bug in the Powershell code?

I don't think it's there. Try first to follow Tom's advice and update to the latest PS version.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby chris.childerhose » Wed Mar 04, 2015 5:28 pm

tsightler wrote:
chris.childerhose wrote:I am running Powershell 2.0 - should it be updated to 3.0 for Veeam 8? Maybe there is something there but I cannot get the jobs with multiple VMs to spit them out in the CSV file. Grrrr :(

I really work suggest upgrading to the lastest Powershell as there are some very strange behaviors if you are running older versions including some of the things you are noting (object methods not returning values, etc).

I believe the primary issue you are having is that you are trying to create a string output, but you are adding array based objects to the list. You'll need some help to actually turn those objects into a simple comma separated string and then add that as a single string property. I'll try to get the script to run in my lab and see what's up as it looks like it would be "easy", but it the meantime I strongly suggest installing WMF 4.0 so that you can get the latest Powershell.


Thanks I will give this a shot and then see what results I get. If you find out the script changes let me know and thanks for the help.

UPDATE: Updated to latest PS and this gives me results in the column but still there is an issue with the multi-VM jobs not showing the VMs selected in the job. The 1 VM jobs show properly. So I think the second statement about creating the string output but adding array based objects is the issue. So I need some assistance with this.
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby tsightler » Wed Mar 04, 2015 6:15 pm

chris.childerhose wrote:UPDATE: Updated to latest PS and this gives me results in the column but still there is an issue with the multi-VM jobs not showing the VMs selected in the job. The 1 VM jobs show properly. So I think the second statement about creating the string output but adding array based objects is the issue. So I need some assistance with this.

There are a couple of ways to attack this, but probably the easiest is just to use the -join option, so something like:
Code: Select all
$Objects = $Job.GetViOijs()
$jobOptions | Add-Member -MemberType NoteProperty -Name "Objects" -value ($Objects.name -join ",")

You've talked about a lot of different code options up above so I'm a little confused about what code you're actually running now. If what I just posted doesn't help post a quick snippet of the code you're currently running that's working for jobs with 1 VM and we'll go from there, but the simple -join should be all you need.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby chris.childerhose » Wed Mar 04, 2015 7:01 pm

tsightler wrote:
chris.childerhose wrote:UPDATE: Updated to latest PS and this gives me results in the column but still there is an issue with the multi-VM jobs not showing the VMs selected in the job. The 1 VM jobs show properly. So I think the second statement about creating the string output but adding array based objects is the issue. So I need some assistance with this.

There are a couple of ways to attack this, but probably the easiest is just to use the -join option, so something like:
Code: Select all
$Objects = $Job.GetViOijs()
$jobOptions | Add-Member -MemberType NoteProperty -Name "Objects" -value ($Objects.name -join ",")

You've talked about a lot of different code options up above so I'm a little confused about what code you're actually running now. If what I just posted doesn't help post a quick snippet of the code you're currently running that's working for jobs with 1 VM and we'll go from there, but the simple -join should be all you need.


That is awesome code and did the trick for my multi-VM jobs to list out all the servers. Thanks so much for the help. :)
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby tsightler » Wed Mar 04, 2015 7:08 pm

Awesome! Glad it worked.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Powershell to get list of VM's in a Veeam backup job

Veeam Logoby chris.childerhose » Wed Mar 04, 2015 9:46 pm

Now I am having a similar issue with the Repository lines of the script. I added the following -

$jobOptions | Add-Member -MemberType NoteProperty -Name "Repository" -value ($repo -join ",")

Now this fixes it but why does this command list all repositories versus per job -

$repo = (Get-VBRBackupRepository | ?{$_.HostId -eq $job.TargetHostId -and $_.Path -eq $job.TargetDir}).name

I just want it to list the repository per job versus per server by the looks of it. Then I would not require the JOIN action.

Any thoughts?
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 71
Liked: 6 times
Joined: Wed Aug 13, 2014 6:03 pm
Location: Toronto, ON
Full Name: Chris Childerhose

PreviousNext

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests