PowerShell script exchange
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 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 »

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
Veeam Vanguard
Posts: 636
Liked: 154 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 »

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 / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
chris.childerhose
Veeam Vanguard
Posts: 636
Liked: 154 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 »

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 / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
veremin
Product Manager
Posts: 20413
Liked: 2301 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 »

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
Veeam Vanguard
Posts: 636
Liked: 154 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 »

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 / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
veremin
Product Manager
Posts: 20413
Liked: 2301 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 »

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
Veeam Vanguard
Posts: 636
Liked: 154 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 »

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 / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
veremin
Product Manager
Posts: 20413
Liked: 2301 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 »

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 »

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
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

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

Post by PTide »

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: 8 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 »

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: 649
Liked: 170 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 »

You may use VMware PowerCLI to get the list of VMs in container, that is found with Get-VBRJobObject.
jimmymc
Service Provider
Posts: 34
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 »

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: 20413
Liked: 2301 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 »

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: 34
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 »

Hi - your code is exactly the same as mine, unless I've missed something?
veremin
Product Manager
Posts: 20413
Liked: 2301 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 »

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: 34
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 » 1 person likes this post

Ha - perfect, thanks and appreciated..

Cheers, James
jimmymc
Service Provider
Posts: 34
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 »

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: 20413
Liked: 2301 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 »

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: 34
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 »

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

Thanks for the help on this..

Cheers, James
nielsengelen
Product Manager
Posts: 5797
Liked: 1215 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 » 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
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
albertwt
Veteran
Posts: 942
Liked: 53 times
Joined: Nov 05, 2009 12:24 pm
Location: Sydney, NSW
Contact:

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

Post by albertwt »

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 ! */
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

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

Post by PTide »

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 »

Hello,

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

Thank you
veremin
Product Manager
Posts: 20413
Liked: 2301 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 »

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: 20
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 »

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 » 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
Veteran
Posts: 942
Liked: 53 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 »

Lidaza,

Can you also please share the script to list the available restore points or the backup retention ?
--
/* Veeam software enthusiast user & supporter ! */
albertwt
Veteran
Posts: 942
Liked: 53 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 »

Hi All,

I cannot use the Object class [Veeam.Backup.Core.CJobCredentials] anymore.

is this now being deprecated in VBR v11a ?

Error:

Code: Select all

Unable to find type [Veeam.Backup.Core.CJobCredentials].
+ ... upCredential           = ([Veeam.Backup.Core.CJobCredentials]::Get($_ ...
+                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Veeam.Backup.Core.CJobCredentials:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound
--
/* Veeam software enthusiast user & supporter ! */
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

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

Post by oleg.feoktistov » 1 person likes this post

Have already answered your question here. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests