PowerShell script exchange
tsightler
VP, Product Management
Posts: 5298
Liked: 2153 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

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

Post by tsightler » 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).

chris.childerhose
Service Provider
Posts: 96
Liked: 12 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

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

Post by chris.childerhose » 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
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

chris.childerhose
Service Provider
Posts: 96
Liked: 12 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

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

Post by chris.childerhose » 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
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

v.eremin
Product Manager
Posts: 16160
Liked: 1320 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by v.eremin » 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.

chris.childerhose
Service Provider
Posts: 96
Liked: 12 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

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

Post by chris.childerhose » 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
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

v.eremin
Product Manager
Posts: 16160
Liked: 1320 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by v.eremin » 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.

chris.childerhose
Service Provider
Posts: 96
Liked: 12 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

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

Post by chris.childerhose » 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
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

v.eremin
Product Manager
Posts: 16160
Liked: 1320 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by v.eremin » 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.

sergio.alegre
Novice
Posts: 4
Liked: never
Joined: Dec 02, 2015 10:54 am
Full Name: Sergio Alegre
Contact:

[MERGED] : List VMs names in a job

Post by sergio.alegre » 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

P.Tide
Product Manager
Posts: 4960
Liked: 419 times
Joined: May 19, 2015 1:46 pm
Contact:

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

Post by P.Tide » 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.

the_mentor
Enthusiast
Posts: 48
Liked: 5 times
Joined: Jul 26, 2012 11:10 pm
Full Name: DeMentor
Contact:

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

Post by the_mentor » 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

nefes
Veeam Software
Posts: 618
Liked: 153 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

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

Post by nefes » 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.

jimmymc
Service Provider
Posts: 30
Liked: 4 times
Joined: Dec 09, 2010 3:06 pm
Contact:

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

Post by jimmymc » 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

v.eremin
Product Manager
Posts: 16160
Liked: 1320 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by v.eremin » 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.

jimmymc
Service Provider
Posts: 30
Liked: 4 times
Joined: Dec 09, 2010 3:06 pm
Contact:

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

Post by jimmymc » Apr 20, 2016 12:28 pm

Hi - your code is exactly the same as mine, unless I've missed something?

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests