PowerShell script exchange
Post Reply
albertwt
Veteran
Posts: 942
Liked: 53 times
Joined: Nov 05, 2009 12:24 pm
Location: Sydney, NSW
Contact:

Exporting the list of VMs that is backed up with Veeam ?

Post by albertwt »

People,

Can anyone here please assist with the Veeam PowerShell script to list all VMs that is currently backed up by Veeam and its backup location (repo), backup time to .CSV file ?

Like this one:

Code: Select all

Foreach ($Job in Get-VBRJob)
{
$job | select name
"-------------------"
$Job |select @{Name="Objectsinjob";Expression={$_.GetObjectsInJob().name}} | select -expandproperty Objectsinjob
" "
}
But it doesn't have the Veeam Backup Job name and when & where is the backup saved ?

Thanks in advance.
--
/* Veeam software enthusiast user & supporter ! */
Andreas Neufert
VP, Product Management
Posts: 7081
Liked: 1511 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Exporting the list of VMs that is backed up with Veeam ?

Post by Andreas Neufert » 1 person likes this post

Enterprise Manager VM tab has this information and you can export it there.
https://helpcenter.veeam.com/docs/backu ... tml?ver=95
albertwt
Veteran
Posts: 942
Liked: 53 times
Joined: Nov 05, 2009 12:24 pm
Location: Sydney, NSW
Contact:

Re: Exporting the list of VMs that is backed up with Veeam ?

Post by albertwt »

Andreas Neufert wrote:Enterprise Manager VM tab has this information and you can export it there.
https://helpcenter.veeam.com/docs/backu ... tml?ver=95
Yes, it works :-)
thanks Andy.
--
/* Veeam software enthusiast user & supporter ! */
twesterd
Influencer
Posts: 17
Liked: 3 times
Joined: May 17, 2017 7:38 pm
Full Name: Trevor W
Contact:

Re: Exporting the list of VMs that is backed up with Veeam ?

Post by twesterd »

How about a PowerShell option? After all, this is a PowerShell forum, not an EM forum. Manually getting info from EM is not the same thing. For example, right now I need to get a list of backup jobs that are contained within a specific repository, then I need to create Backup Copy jobs to maintain offsite copies (if the job isn't already created). The idea is to automate this where a service compares what is in a repository to auto-generate as necessary. Manually getting the list defeats the purpose.

So, Is there a way... in PowerShell?
twesterd
Influencer
Posts: 17
Liked: 3 times
Joined: May 17, 2017 7:38 pm
Full Name: Trevor W
Contact:

Re: Exporting the list of VMs that is backed up with Veeam ?

Post by twesterd »

Also, I looked at the EM link, then I just exported the data in my environment. For us, there is a significant flaw in that report. The column for "job name" is NOT the job name, it is the folder name in the repository with the underscores removed. We had a need to move all our jobs to scale out repositories and after that change Veeam sees the backups having two locations (we worked with Veeam support on this and there is no way to merge them back).

Also, if you change the name of a job, the folder name does not change, so the "job name" in the report will reflect the original job name, not the current name because what is listed as "job name" is really folder name. Because of issues like this it is unreliable for our automation purposes.
nielsengelen
Product Manager
Posts: 5797
Liked: 1215 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Exporting the list of VMs that is backed up with Veeam ?

Post by nielsengelen » 1 person likes this post

There are a few posts on the forums about this; have a look at powershell-f26/list-vm-s-which-are-back ... ml#p221539
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
weaversp
Novice
Posts: 3
Liked: never
Joined: May 03, 2016 8:11 am
Full Name: Stephen Weaver
Contact:

Re: Exporting the list of VMs that is backed up with Veeam ?

Post by weaversp »

Hi

B&R 11

I know this one is a bit old, but I am trying to export a list of all VM's with no other information to CSV,
output to the console is exactly what I need, but cannot get it to go to CSV, what am I missing?

Thanks in advance

Code: Select all


$summary = @()
Foreach ($Job in Get-VBRJob)
{
$Job |select @{Name="Objectsinjob";Expression={$_.GetObjectsInJob().name}} | select -expandproperty Objectsinjob

# This outputs a cvs list of nothing
#$Job |select @{Name="Objectsinjob";Expression={$_.GetObjectsInJob().name}} | select -expandproperty Objectsinjob | export-csv C:\list_all_vms.csv -Append

# This outputs a CSV list of numbers
#$summary += ($Job |select @{Name="Objectsinjob";Expression={$_.GetObjectsInJob().name}} | select -expandproperty Objectsinjob)

# This outputs a cvs list of the Job Description only
#$summary += $Job | select Name, Objectsinjob

# This outputs a cvs list of nothing
#$summary += $Job | select Objectsinjob

# This outputs a cvs list of nothing
#$summary += $Job | select Expression

}

# Simple file rename with current date and time
$summary | Export-Csv -Path 'C:\list_all_vms.csv'
$filenameFormat = "list_all_vms" + "_" + (Get-Date -Format "yyyy-MM-dd_HH-mm-ss") + ".csv"
Rename-Item -Path "C:\list_all_vms.csv" -NewName $filenameFormat

david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Exporting the list of VMs that is backed up with Veeam ?

Post by david.domask » 1 person likes this post

Hi @weaversp,

When you pipe the $job content to the select statement, a new PSCustomObject is made in powershell that only has those properties. So lines like:

#$summary += ($Job |select @{Name="Objectsinjob";Expression={$_.GetObjectsInJob().name}} | select -expandproperty Objectsinjob)

Will simply pass the ObjectInJob property, and it will not be "expanded".

Don't assume how the output looks in the shell is how it will look in a text file -- remember, Powershell is object oriented, and a lot of the objects will be formatted specifically.

I would use the following code to build your list (your current code uses unsupported methods):

Code: Select all

$jobs = Get-VBRJob
$ObjectsInJobSummary = [System.Collections.Generic.List[PSObject]]@()
Foreach($j in $jobs){
	$jObjs = Get-VBRJobObject -Job $j
	$ObjectsInJobSummary.Add($jObjs)
	}
$ObjectsInJobSummary

Name                      Type       ApproxSize       Location
----                      ----       ----------       --------
DDOM-VEEAM-RB4            Include    0 B
ddom-tinyvm               Include    0 B              somevcenter.vvvvv.local...
F:\perjobbackups          Include    0 B              F:\perjobbackups
F:\quick-encrypt-test     Include    0 B              F:\quick-encrypt-test
F:\snap-redirect-test-... Include    0 B              F:\snap-redirect-test-...
F:\snap-redirect-test-... Include    0 B              F:\snap-redirect-test-...
ddom-tinyvm               Include    0 B              somevcenter.vvvvv.local...
ddom-tinyvm               Include    0 B              somevcenter.vvvvv.local...
ddom-tinyvm               Include    0 B              somevcenter.vvvvv.local...
ddom-tinyvm_replica       Include    1024 KB          somevcenter.vvvvv.local...
ddom-tinyvm               Include    0 B              somevcenter.vvvvv.local...
ddom-tinyvm_replica       Include    1024 KB          somevcenter.vvvvv.local...
ddom-debian-backmeup      Include    16 GB            somevcenter.vvvvv.local...
That will build your core data, then all you need to do is format it. Try calling first item from the index of the report ( $ObjectsInJobSummary[0] ) and make PSCustomObjects of the data you want to be part of the report, then write that to a report file. This is the appropriate place to pipe to select, but you will need to decide what you want to see in your report.
David Domask | Product Management: Principal Analyst
weaversp
Novice
Posts: 3
Liked: never
Joined: May 03, 2016 8:11 am
Full Name: Stephen Weaver
Contact:

Re: Exporting the list of VMs that is backed up with Veeam ?

Post by weaversp »

Hi David

Will give it go, new to Powershell, still learning.

Many Thanks.
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Exporting the list of VMs that is backed up with Veeam ?

Post by david.domask »

Always welcome good luck.

> new to Powershell, still learning.

Aha, I think it's a good project to cut your teeth on.

>[System.Collections.Generic.List[PSObject]]@()

Just some early tips/advice, don't fret on what this is doing right now, it's just a better way to add items to an array. += works, but it clones the array in memory each time it's called, and for large datasets this can get really slow.

Microsoft's PS documentation is surprisingly well made, so I'd recommend review this about how to create a PSCustomObject, as I suspect you'll want this for your report:

https://learn.microsoft.com/en-us/power ... rshell-7.3

You could edit the ForEach loop to add a line like:

$ReportObject = [PSCustomObject]@{
JobName = $j.Name
ObjectName = $JObjs.Name
}
$ObjectsInJobSummary.Add($ReportObject)

That would add the individual object to that report; keep in mind, $jObjs in my example code will be _an array of the results returned by Get-VBRJobObject_, so you may need an additional loop over the items in $jObjs to make a PSCustomObject for each. Usually nested ForEach/For loops is not recommended, but in this case it shouldn't be too traumatic for your script :)
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests