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 tsightler » Thu Mar 05, 2015 1:04 am

chris.childerhose wrote: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 don't know, it works fine for me. At first guess I'm thinking you are possibly using SMB/CIFS/DDboost repos with the gateway set to "auto" which technically means they are all owned by the same host and perhaps even using the same path. Since the line above is matching the TargetHostId and TargetDir that's one scenario that would lead to duplicates.

Honestly though, that feels like a pretty complex way to get repo information when you already have the job object right there. I'd suggest just deleting those two lines dealing with the repository completely and replacing it with the following much simpler solution:
Code: Select all
$jobOptions | Add-Member -MemberType NoteProperty -Name "Repository" -value $job.GetTargetRepository().Name

Should be way more efficient and won't have any problem returning mulitple repos or anything like that no matter what (or at least it shouldn't).
tsightler
Veeam Software
 
Posts: 4872
Liked: 1821 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 » Thu Mar 05, 2015 3:15 pm

I removed those 2 lines and added the line you suggested. Works much better and lists only the job repository versus all of them for the backup host. Thanks again! 8)
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 77
Liked: 8 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 chris.childerhose » Tue Mar 17, 2015 3:59 pm

One more request for my script. There is a line that tries to retrieve the credentials for the VSS Options but it is coming up blank -

$jobOptions | Add-Member -MemberType NoteProperty -Name "VSS Username" -Value $($job | get-vbrjobvssoptions).credentials.username

I believe the end part in bold is wrong. What would be the correct syntax as I haven't found anything useful in the Powershell help or online.

Thanks
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 77
Liked: 8 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 » Tue Mar 17, 2015 4:12 pm

Try something like this. It's sort of creative workaround. Unfortunately, I don't know the easier way.

Code: Select all
$jobOptions | Add-Member -MemberType NoteProperty -Name "VSS Username" -Value [Veeam.Backup.Core.CJobCredentials]::Get($Job.Id).CredentialsInfo.Credentials.UserName

Thanks.
v.Eremin
Veeam Software
 
Posts: 13709
Liked: 1025 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 » Tue Mar 17, 2015 5:18 pm

Tried changing that line and got this error -

Code: Select all
Add-Member : The SecondValue parameter is not necessary for a member of type "NoteProperty", and should not be
specified. Do not specify the SecondValue parameter when you add members of this type.
At C:\Util\VeeamJobDetail.ps1:132 char:16
+     $jobOptions | Add-Member -MemberType NoteProperty -Name "VSS Username" -Value [ ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Add-Member], InvalidOperationException
    + FullyQualifiedErrorId : Value2ShouldNotBeSpecified,Microsoft.PowerShell.Commands.AddMemberCommand


So not sure if that works correctly.
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 77
Liked: 8 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 18, 2015 11:00 am

Try to put the provided portion into the brackets and see whether it makes any difference?

Code: Select all
$jobOptions | Add-Member -MemberType NoteProperty -Name "VSS Username" -Value ([Veeam.Backup.Core.CJobCredentials]::Get($Job.Id).CredentialsInfo.Credentials.UserName)


Thanks.
v.Eremin
Veeam Software
 
Posts: 13709
Liked: 1025 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 » Mon Mar 23, 2015 5:08 pm

That worked thank you. I also had to add the -join construct as some jobs had more than one credential and it did not show properly. Full line is this with the changed part in bold -

$jobOptions | Add-Member -MemberType NoteProperty -Name "VSS Username" -Value ([Veeam.Backup.Core.CJobCredentials]::Get($Job.Id).CredentialsInfo.Credentials.UserName -join ",")
Chris Childerhose, VCAP-DCA, VMCE9, VCP, MCITP
chris.childerhose
Enthusiast
 
Posts: 77
Liked: 8 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 » Tue Mar 24, 2015 11:31 am

Yep, in case of multiple credentials -join parameter should be used. As to getting credentials with the use of ID, we understand that current approach is far from ideal (it's more or less workaround), and plan to add -ID parameter to Get-VBRCredentials in the future. Thanks.
v.Eremin
Veeam Software
 
Posts: 13709
Liked: 1025 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

[MERGED] : List VMs names in a job

Veeam Logoby sergio.alegre » Wed Dec 02, 2015 11:17 am

My first post here. Wish the first of many others.

I have review the cmdlets list, and i'm not able to find how lo make a list with VM name in a job.

Do you know how can i get the VM list on a single job (i have a lot of jobs):

Get-VBRJob | Where {$_.Name -like "SPB*"}

Thanks in advance
sergio.alegre
Novice
 
Posts: 3
Liked: never
Joined: Wed Dec 02, 2015 10:54 am
Full Name: Sergio Alegre

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

Veeam Logoby PTide » Wed Dec 02, 2015 11:25 am

Hi,

You topic has been merged. Please see this post. Kindly use forum search engine prior to posting - it's possible that your question (or similar) has been already answered.

Should you have any questions please let us know.

Thank you.
PTide
Veeam Software
 
Posts: 3245
Liked: 272 times
Joined: Tue May 19, 2015 1:46 pm

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

Veeam Logoby the_mentor » Wed Feb 03, 2016 6:25 pm

I am looking for a way to list all VMs including ones in Vmware Folders but it seems that GetObjectsInJob() and Get-VBRJobObject list the folder name not the VMs inside that folder.
Is there a way to get a list of VMs inside the folder?
-DeMentor
the_mentor
Enthusiast
 
Posts: 42
Liked: 5 times
Joined: Thu Jul 26, 2012 11:10 pm
Full Name: DeMentor

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

Veeam Logoby nefes » Wed Feb 03, 2016 8:09 pm

You may use VMware PowerCLI to get the list of VMs in container, that is found with Get-VBRJobObject.
nefes
Veeam Software
 
Posts: 552
Liked: 129 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

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

Veeam Logoby jimmymc » Wed Apr 20, 2016 10:57 am

Hi All

I'm using the scripts in this post to grab job details, but I'd also like to know whether SAN Snapshots are enabled for each job. I've inserted the following line:

Code: Select all
$jobOptions | Add-Member -MemberType NoteProperty -Name "Storage Snapshots" -Value $job.SanIntegrationOptions.UseSanSnapshots


But the results are blank. Could someone point out where I'm going wrong? (Powershell newbie)

Cheers, James
jimmymc
Service Provider
 
Posts: 29
Liked: 3 times
Joined: Thu Dec 09, 2010 3:06 pm

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

Veeam Logoby v.Eremin » Wed Apr 20, 2016 11:48 am

You seem to have missed Options root property. Try the following example:
Code: Select all
$jobOptions | Add-Member -MemberType NoteProperty -Name "Storage Snapshots" -Value $job.Options.SanIntegrationOptions.UseSanSnapshots


Thanks.
v.Eremin
Veeam Software
 
Posts: 13709
Liked: 1025 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 jimmymc » Wed Apr 20, 2016 12:28 pm

Hi - your code is exactly the same as mine, unless I've missed something?
jimmymc
Service Provider
 
Posts: 29
Liked: 3 times
Joined: Thu Dec 09, 2010 3:06 pm

PreviousNext

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 1 guest