PowerShell script exchange
tsightler
VP, Product Management
Posts: 5418
Liked: 2240 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: 110
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: 110
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

veremin
Product Manager
Posts: 16879
Liked: 1429 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 veremin » 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: 110
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

veremin
Product Manager
Posts: 16879
Liked: 1429 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 veremin » 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: 110
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

veremin
Product Manager
Posts: 16879
Liked: 1429 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 veremin » 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: 5260
Liked: 459 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: 628
Liked: 156 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

veremin
Product Manager
Posts: 16879
Liked: 1429 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 veremin » 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?

veremin
Product Manager
Posts: 16879
Liked: 1429 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 veremin » Apr 20, 2016 12:45 pm

Apologize. I hadn't been fast enough to update the code before you spotted. :)

The missing part was .Options. between $Job and .SanIntegrationOptions.

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 1:09 pm 1 person likes this post

Ha - perfect, thanks and appreciated..

Cheers, James

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 22, 2016 2:05 pm

Sorry, one more thing! As well as the options for each job (which is working great), I'm trying to get a count of VMs within each job tagged on the end (not 'objects' per-se, as it may well list a folder as an object). Could someone help out with adding this?

Thanks again in advance..

Cheers, James

veremin
Product Manager
Posts: 16879
Liked: 1429 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 veremin » Apr 25, 2016 9:45 am

So, what is selected as a job source - individual VMs or container, such as folder, resource pool and so on? Based on the source settings, the approach might vary. 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 25, 2016 10:08 am

Hi - All our jobs are based on folders thanks.. there are sub-folders of course..

Thanks for the help on this..

Cheers, James

nielsengelen
Veeam Software
Posts: 2634
Liked: 540 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

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

Post by nielsengelen » Apr 25, 2016 11:20 am 1 person likes this post

The following script counts the VM's within a folder in a job:

Code: Select all

asnp veeampssnapin

$jobs = Get-VBRJob -Name "BACKUPJOBWITHFOLDERS"

$vms = 0
$objects = $jobs.GetObjectsInJob()
$type = $objects.GetObject().Type

foreach ($object in $objects) {
    $type = $object.GetObject().Type
               
    if ($type -eq "VM") {
        $vms++
    } else {
        $jvm = Find-VBRViEntity -VMsAndTemplates -Server (Get-VBRServer) | Where { $_.VmFolderName -eq $object.Name }
    }
}

foreach ($vm in $jvm) {
    $vms++
}

Write-Output $vms
VCP-DCV
Veeam Certified Architect (VMCA)
http://foonet.be

albertwt
Expert
Posts: 640
Liked: 20 times
Joined: Nov 05, 2009 12:24 pm
Location: Sydney, NSW
Contact:

[MERGED] Using Powershell to get backup job AD account ?

Post by albertwt » Jun 16, 2016 4:59 am

Hi All,

I was looking for a way to get the list of the Backup job and its Service account / credentials that is in use with Veeam Powershell.
Is that possible ?

Because my predecessor was setting all of the backup job (~78 in total) with DOMAIN\Administrator which now has to be changed with the proper service account.
Any help on the Powershell script would be greatly appreciated.

Thanks.
--
/* Veeam software enthusiast user & supporter ! */

P.Tide
Product Manager
Posts: 5260
Liked: 459 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 » Jun 16, 2016 2:36 pm

Hi,

Please check this post

Thanks

ldasilva
Novice
Posts: 5
Liked: never
Joined: Apr 25, 2017 5:43 pm
Full Name: Lisandro da Silva
Contact:

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

Post by ldasilva » Apr 26, 2017 4:22 pm

Hello,

Is there a way i can get a copy of the finished script?

Thank you

veremin
Product Manager
Posts: 16879
Liked: 1429 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 veremin » Apr 26, 2017 6:54 pm

Can you provide an answer to the question asked above - what is selected as backup job source? Container or individual VMs?

SeRo
Service Provider
Posts: 17
Liked: never
Joined: Mar 31, 2017 8:17 am
Contact:

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

Post by SeRo » Sep 10, 2018 8:59 am

Hello everyone,

I am working on a powershell script to export the following parameter:

- List all backup jobs
- List all VMs in each backup job
- List the size of each VM based on the size which is shown in the backup editing screen while adding a new virtual machine.

Can someone help me? All I get is a list with all backup jobs with the last "processed data". But thats not what I want.

lidaza
Lurker
Posts: 2
Liked: 2 times
Joined: Feb 05, 2016 10:19 am
Full Name: Lidaza
Contact:

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

Post by lidaza » Oct 11, 2018 2:02 pm 2 people like this post

SeRo wrote:
Sep 10, 2018 8:59 am
Hello everyone,

I am working on a powershell script to export the following parameter:

- List all backup jobs
- List all VMs in each backup job
- List the size of each VM based on the size which is shown in the backup editing screen while adding a new virtual machine.

Can someone help me? All I get is a list with all backup jobs with the last "processed data". But thats not what I want.
Try this:

Code: Select all

Get-VBRJob | ?{$_.JobType -eq "Backup"} | %{
	$JobName = $_.Name
	$_ | Get-VBRJobObject | ?{$_.Object.Type -eq "VM"} | Select @{ L="Job"; E={$JobName}}, Name, @{ L="Size"; E={$_.ApproxSizeString}} | Sort -Property Job, Name
}

albertwt
Expert
Posts: 640
Liked: 20 times
Joined: Nov 05, 2009 12:24 pm
Location: Sydney, NSW
Contact:

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

Post by albertwt » Feb 20, 2019 6:18 am

Lidaza,

Can you also please share the script to list the available restore points or the backup retention ?
--
/* Veeam software enthusiast user & supporter ! */

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests