PowerShell script exchange
chamdor
Influencer
Posts: 23
Liked: 1 time
Joined: Jun 15, 2009 7:00 pm
Contact:

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

Post by chamdor » Mar 16, 2010 3:57 am 1 person likes this post

Hi,

It doesn't appear that I can use Veeam's Powershell integration to get a list of VM's in a backup job. What I want to do ( in PowerShell ) is have a list of backup jobs, and the list of VM's in those jobs. Any tips on how to get the list of VM's in a job appreciated.

Gostev
SVP, Product Management
Posts: 24612
Liked: 3458 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

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

Post by Gostev » Mar 16, 2010 11:40 am 1 person likes this post

Hello,

List of all backup jobs (that's an easy one) ;)

Code: Select all

Get-VBRJob
List of all VMs per job

Code: Select all

foreach($job in Get-VBRJob) { Write-Host "Job:", $job.Name; $job.GetObjectsInJob() | foreach { $_.Location } }

chamdor
Influencer
Posts: 23
Liked: 1 time
Joined: Jun 15, 2009 7:00 pm
Contact:

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

Post by chamdor » Mar 16, 2010 1:38 pm

Awesome thanks. :-)

Andreas Neufert
Veeam Software
Posts: 3747
Liked: 665 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

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

Post by Andreas Neufert » Feb 27, 2015 2:54 pm

Just a v8 Update from a customer request...

List all VMs from a Job

Code: Select all

asnp VeeamPSSnapin
$JobnName = "YourJobName"
$JobObject = Get-VBRJob -name $JobnName
$Objects = $JobObject.GetObjectsInJob()
$Objects.name
List all Jobs

Code: Select all

asnp VeeamPSSnapin
$JobList = Get-VBRJob
$JobList.Name
List all VMs (unformated and undeduplicated) from all Jobs.

Code: Select all

asnp VeeamPSSnapin
$JobList = Get-VBRJob
foreach($Jobobject in $JobList)
{$Objects = $JobObject.GetObjectsInJob()
$Objects.name}

chris.childerhose
Service Provider
Posts: 107
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 02, 2015 4:47 pm

I am trying to use a script floating around that gives you job details but it does not have the Server names. How would I add this to the script?

Script -

Code: Select all

#--------------------------------------------------------------------
# Parameters
param (
	[Parameter(mandatory=$false)] [String]$path

)

#--------------------------------------------------------------------
# User Defined Variables

# Open csv file after creation
$autoLaunch = $false

#--------------------------------------------------------------------
# Static Variables

$scriptName = "VeeamJobDetail"
$scriptVer = "1.0"
$scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$starttime = Get-Date -uformat "%m-%d-%Y %I:%M:%S"
$allDetails = @()

#--------------------------------------------------------------------
# Load Snap-ins

# Add Veeam snap-in if required
If ((Get-PSSnapin -Name VeeamPSSnapin -ErrorAction SilentlyContinue) -eq $null) {add-pssnapin VeeamPSSnapin}

#--------------------------------------------------------------------
# Functions

#--------------------------------------------------------------------
# Main Procedures

Clear-Host
Write-Host "********************************************************************************"
Write-Host "$scriptName`tVer:$scriptVer`t`t`tStart Time:`t$starttime"
Write-Host "********************************************************************************`n"

# Get Backup Jobs
$jobs = Get-VBRJob | ?{$_.JobType -eq "Backup"}

# Loop through each job adding details to array
foreach ($job in $jobs) {
	$jobOptions = New-Object PSObject
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Name" -value $job.name
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Enabled" -value $job.isscheduleenabled
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Backup Mode" -value $job.backuptargetoptions.algorithm
	$repo = (Get-VBRBackupRepository | ?{$_.HostId -eq $job.TargetHostId -and $_.Path -eq $job.TargetDir}).name
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Repository" -value $repo
	$proxies = $null
	foreach ($prox in ($job | get-vbrjobproxy)) {
		$pName = $prox.Name
		$proxies = $proxies + $pName
	}
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Proxy" -value $proxies
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Auto Proxy" -Value $job.sourceproxyautodetect
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Next Run" -Value $job.scheduleoptions.nextrun
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Restore Points" -Value $job.backupstorageoptions.retaincycles
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Deduplication" -Value $job.backupstorageoptions.enablededuplication
	$comp = $job.backupstorageoptions.compressionlevel
	If ($comp -eq 0) {$comp = "None"}
	If ($comp -eq 4) {$comp = "Dedupe Friendly"}
	If ($comp -eq 5) {$comp = "Optimal"}
	If ($comp -eq 6) {$comp = "High"}
	If ($comp -eq 9) {$comp = "Extreme"}
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Compression" -Value $comp
	$opti = $job.backupstorageoptions.stgblocksize
	If ($opti -eq "KbBlockSize8192") {$opti = "Local Target(16TB+ Files)"}
	If ($opti -eq "KbBlockSize1024") {$opti = "Local Target"}
	If ($opti -eq "KbBlockSize512") {$opti = "LAN Target"}
	If ($opti -eq "KbBlockSize256") {$opti = "WAN Target"}
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Optimized" -Value $opti
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Integrity Checks" -Value $job.backupstorageoptions.enableintegritychecks
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Exclude Swap" -Value $job.visourceoptions.excludeswapfile
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Remove Deleted VMs" -Value $job.backupstorageoptions.enabledeletedvmdataretention
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Retain Deleted VMs" -Value $job.backupstorageoptions.retaindays
	$jobOptions | Add-Member -MemberType NoteProperty -Name "CBT Enabled" -Value $job.visourceoptions.usechangetracking
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Auto Enable CBT" -Value $job.visourceoptions.enablechangetracking
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Set VM Note" -Value $job.visourceoptions.setresultstovmnotes
	$jobOptions | Add-Member -MemberType NoteProperty -Name "VM Attribute Name" -Value $job.visourceoptions.vmattributename
	$jobOptions | Add-Member -MemberType NoteProperty -Name "VMTools Quiesce" -Value $job.visourceoptions.vmtoolsquiesce
	$jobOptions | Add-Member -MemberType NoteProperty -Name "VSS Enabled" -Value $job.vssoptions.enabled
	$igfs = $job.vssoptions.guestfsindexingtype
	If ($igfs -eq "None") {$igfs = "Disabled"}
	ElseIf ($igfs -eq "EveryFolders") {$igfs = "Enabled"}
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Index Guest FS" -Value $igfs
	$jobOptions | Add-Member -MemberType NoteProperty -Name "VSS Username" -Value $($job | get-vbrjobvssoptions).credentials.username
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Description" -Value $job.Description
	$allDetails += $jobOptions
}

#--------------------------------------------------------------------
# Outputs

# Display results summary
$allDetails | select Name, Enabled | Sort Name | ft -AutoSize

If (!$path -or !$path.EndsWith(".csv")) {
	Write-Host "`n`nUsing Default Path"
	$path = $scriptDir + "\" + $scriptName + "_" + (Get-Date -uformat %m-%d-%Y_%I-%M-%S) + ".csv"
	$path
} Else {
	Write-Host "`n`nUsing Supplied Path"
	$path
}

# Export results
$allDetails | Sort Name | Export-Csv $path -NoTypeInformation -Force

# Open csv
If ($autoLaunch) {
	Invoke-Item $path
}

$finishtime = Get-Date -uformat "%m-%d-%Y %I:%M:%S"
Write-Host "`n`n"
Write-Host "********************************************************************************"
Write-Host "$scriptName`t`t`t`tFinish Time:`t$finishtime"
Write-Host "********************************************************************************"

# Prompt to exit script - This leaves PS window open when run via right-click
Write-Host "`n`n"
Write-Host "Press any key to continue ..." -foregroundcolor Gray
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

veremin
Product Manager
Posts: 16778
Liked: 1404 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 02, 2015 5:04 pm

You need to place the following string inside the loop:

Code: Select all

$Objects = $Job.GetObjectsInJob()
And, then, assign $Objects as one of the properties of $JobOptions variable.

Thanks.

chris.childerhose
Service Provider
Posts: 107
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 02, 2015 5:13 pm

I put it in the loop and assigned it but getting unusual output in the CSV file. Is this right for adding the code to the loop?

Code: Select all

foreach ($job in $jobs) {
	$Objects = $Job.GetObjectsInJob()
	$jobOptions = New-Object PSObject
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Name" -value $job.name
	$jobOptions | Add-Member -MemberType NoteProperty -Name "Servers" -value $Objects
What this gives me for the Servers column -

Code: Select all

Veeam.Backup.Core.CObjectInJob[]
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

veremin
Product Manager
Posts: 16778
Liked: 1404 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 03, 2015 10:09 am

What happens if you try to assign only object names, not objects as a whole?

Code: Select all

foreach ($job in $jobs) {
$Objects = $Job.GetObjectsInJob() | select name
$jobOptions = New-Object PSObject
$jobOptions | Add-Member -MemberType NoteProperty -Name "Name" -value $job.name
$jobOptions | Add-Member -MemberType NoteProperty -Name "Servers" -value $Objects
Thanks.

chris.childerhose
Service Provider
Posts: 107
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 03, 2015 2:25 pm

When I do it this way I get mostly this in the column -

System.Object[]

I did get one to show this -

@{Name=SERVERA}

So a little closer but there is something missing. Any other thoughts?
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

chris.childerhose
Service Provider
Posts: 107
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 03, 2015 2:38 pm

If I change this line I get one job showing the VM in the job but none of the others show which have more than 1 VM -

$jobOptions | Add-Member -MemberType NoteProperty -Name "Servers" -value $Objects

New Value

$jobOptions | Add-Member -MemberType NoteProperty -Name "Servers" -value $Objects.name

So not sure why it is not getting the jobs with multiple VMs to show.

UPDATE - So it appears jobs with multiple VMs this does not work on for some reason. Any job with 1 VM works perfect with this code update. Any thoughts?
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

veremin
Product Manager
Posts: 16778
Liked: 1404 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 03, 2015 2:55 pm

With the following code, even if there are multiple VMs chosen as a source for a backup job, all of them should be listed in the similar format:

Code: Select all

Name                                                                                                             Objects                                                                                                        
----                                                                                                             -------                                                                                                        
Backup Job 5                                                                                                     {HyperServ_replica, HyperServ_replica_temp}          


Code:

Code: Select all

foreach ($job in Get-VBRJob) {
   $jobOptions = New-Object PSObject
   
   $Objects = $Job | Get-VBRJobObject 
   
   $jobOptions | Add-Member -MemberType NoteProperty -Name "Name" -value $job.name
   $jobOptions | Add-Member -MemberType NoteProperty -Name "Objects" -value $Objects.name

 }
 

chris.childerhose
Service Provider
Posts: 107
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 03, 2015 3:12 pm

I tried changing the code and for some reason any job with multiple VMs it is not picking them up. No matter what I do.

I am running Powershell 2.0 - should it be updated to 3.0 for Veeam 8? Maybe there is something there but I cannot get the jobs with multiple VMs to spit them out in the CSV file. Grrrr :(
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

veremin
Product Manager
Posts: 16778
Liked: 1404 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 03, 2015 3:20 pm

Are those VMs selected individually or added through containers, such as Resource Pool, folder, hosts, etc.?

What happens if you query a job in question outside of this script?

Code: Select all

$Job = Get-VBRJob -name "Name of your backup job"
$Objects = $Job | Get-VBRJobObject 
$Objects.name
Thanks.

chris.childerhose
Service Provider
Posts: 107
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 03, 2015 3:37 pm

They are selected individually when added to the job from the VC. I use the CTRL key to select multiples when expanding my Cluster.

I will try the query outside the script and see.

UPDATE - How do I output that query to the screen? Sorry having brain fart this morning. This line seems to work just to query the jobs and displays the VMs in each job -

foreach($job in Get-VBRJob) { Write-Host "Job:", $job.Name; $job.GetObjectsInJob() | foreach { $_.Location } }
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

chris.childerhose
Service Provider
Posts: 107
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 03, 2015 8:43 pm

I changed the line code for $Objects to this -

$Objects = $job | Get-VBRJobObject

This seems to work for adding the VMs to the column I need but still only pulls the single VM jobs and not jobs with more than 1 VM. Starting to pull my hair out now! :lol:
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

veremin
Product Manager
Posts: 16778
Liked: 1404 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 04, 2015 11:11 am

How do I output that query to the screen?
Just open a PS, and input the mentioned script line by line. The last line should output the VM objects to the screen.
I need but still only pulls the single VM jobs and not jobs with more than 1 VM.
So, the script doesn't list jobs containing more than one VM as source or it lists only the first VM for such jobs?

chris.childerhose
Service Provider
Posts: 107
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 04, 2015 3:08 pm

It does not list any job with more than 1 VM selected within it. If the job has only 1 VM selected it is listed for my column in the CSV file. Not sure why this is the case but if I cannot figure it out I will populate the spreadsheet for those jobs manually. Would have been nice to automate it.

I ran the lines you mentioned one at a time on a job with 3 VMs within it and the last line did not display anything. I then ran the same lines on a job with 1 VM and it showed the name of the VM.
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

veremin
Product Manager
Posts: 16778
Liked: 1404 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 04, 2015 3:14 pm

Hmm, interesting. Do those variables at least contain something or not?

Code: Select all

$Job = Get-VBRJob -name "Name of your backup job with multiple VMs"
$Job
$Objects = $Job | Get-VBRJobObject 
$Objects
Thanks.

chris.childerhose
Service Provider
Posts: 107
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 04, 2015 3:42 pm

The first variable $Job contains something with either jobs - single or multiple VMs. The second variable $Objects does not contain anything for the multiple VM jobs but does for the single VM jobs. It is weird.
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

veremin
Product Manager
Posts: 16778
Liked: 1404 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 04, 2015 3:50 pm

Agree, absolutely strange behaviour as to me.

And VM objects don't get populated via PS regardless of used approach?

Code: Select all

$Job = Get-VBRJob -name "Name of your backup Job"
$Job.GetViOijs()

$Job.GetObjectsInJob()
Thanks.

chris.childerhose
Service Provider
Posts: 107
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 04, 2015 3:56 pm

v.Eremin wrote:Agree, absolutely strange behaviour as to me.

And VM objects don't get populated via PS regardless of used approach?

Code: Select all

$Job = Get-VBRJob -name "Name of your backup Job"
$Job.GetViOijs()

$Job.GetObjectsInJob()
Thanks.
When using these methods I can see all VMs in a multi-VM job. Both variables display the VMs.
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

veremin
Product Manager
Posts: 16778
Liked: 1404 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 04, 2015 4:31 pm

Ok, so what if you integrate this part into the referenced code?

Code: Select all

    foreach ($job in Get-VBRJob) {
       $jobOptions = New-Object PSObject
       
       $Objects = $Job.GetViOijs()
       
       $jobOptions | Add-Member -MemberType NoteProperty -Name "Name" -value $job.name
       $jobOptions | Add-Member -MemberType NoteProperty -Name "Objects" -value $Objects.name
}
Thanks.

chris.childerhose
Service Provider
Posts: 107
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 04, 2015 4:41 pm

v.Eremin wrote:Ok, so what if you integrate this part into the referenced code?

Code: Select all

    foreach ($job in Get-VBRJob) {
       $jobOptions = New-Object PSObject
       
       $Objects = $Job.GetViOijs()
       
       $jobOptions | Add-Member -MemberType NoteProperty -Name "Name" -value $job.name
       $jobOptions | Add-Member -MemberType NoteProperty -Name "Objects" -value $Objects.name
}
Thanks.
Nope that doesn't work and does not show even jobs with 1 VM in it. I then replace it with this and it shows my 1 VM jobs fine but not multiple VM jobs -

$Objects = Get-VBRJobObject $job

So I am stumped and going to manually populate my spreadsheets for now. Maybe this is a bug in the Powershell code?
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

tsightler
VP, Product Management
Posts: 5399
Liked: 2229 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 04, 2015 5:24 pm

chris.childerhose wrote:I am running Powershell 2.0 - should it be updated to 3.0 for Veeam 8? Maybe there is something there but I cannot get the jobs with multiple VMs to spit them out in the CSV file. Grrrr :(
I really would suggest upgrading to the lastest Powershell as there are some very strange behaviors if you are running older versions including some of the things you are noting (object methods not returning values, etc).

I believe the primary issue you are having is that you are trying to create a string output, but you are adding array based objects to the list. You'll need some help to actually turn those objects into a simple comma separated string and then add that as a single string property. I'll try to get the script to run in my lab and see what's up as it looks like it would be "easy", but it the meantime I strongly suggest installing WMF 4.0 so that you can get the latest Powershell.

veremin
Product Manager
Posts: 16778
Liked: 1404 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 04, 2015 5:27 pm

Maybe this is a bug in the Powershell code?
I don't think it's there. Try first to follow Tom's advice and update to the latest PS version.

chris.childerhose
Service Provider
Posts: 107
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 04, 2015 5:28 pm

tsightler wrote: I really work suggest upgrading to the lastest Powershell as there are some very strange behaviors if you are running older versions including some of the things you are noting (object methods not returning values, etc).

I believe the primary issue you are having is that you are trying to create a string output, but you are adding array based objects to the list. You'll need some help to actually turn those objects into a simple comma separated string and then add that as a single string property. I'll try to get the script to run in my lab and see what's up as it looks like it would be "easy", but it the meantime I strongly suggest installing WMF 4.0 so that you can get the latest Powershell.
Thanks I will give this a shot and then see what results I get. If you find out the script changes let me know and thanks for the help.

UPDATE: Updated to latest PS and this gives me results in the column but still there is an issue with the multi-VM jobs not showing the VMs selected in the job. The 1 VM jobs show properly. So I think the second statement about creating the string output but adding array based objects is the issue. So I need some assistance with this.
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

tsightler
VP, Product Management
Posts: 5399
Liked: 2229 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 04, 2015 6:15 pm

chris.childerhose wrote:UPDATE: Updated to latest PS and this gives me results in the column but still there is an issue with the multi-VM jobs not showing the VMs selected in the job. The 1 VM jobs show properly. So I think the second statement about creating the string output but adding array based objects is the issue. So I need some assistance with this.
There are a couple of ways to attack this, but probably the easiest is just to use the -join option, so something like:

Code: Select all

$Objects = $Job.GetViOijs()
$jobOptions | Add-Member -MemberType NoteProperty -Name "Objects" -value ($Objects.name -join ",")
You've talked about a lot of different code options up above so I'm a little confused about what code you're actually running now. If what I just posted doesn't help post a quick snippet of the code you're currently running that's working for jobs with 1 VM and we'll go from there, but the simple -join should be all you need.

chris.childerhose
Service Provider
Posts: 107
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 04, 2015 7:01 pm

tsightler wrote: There are a couple of ways to attack this, but probably the easiest is just to use the -join option, so something like:

Code: Select all

$Objects = $Job.GetViOijs()
$jobOptions | Add-Member -MemberType NoteProperty -Name "Objects" -value ($Objects.name -join ",")
You've talked about a lot of different code options up above so I'm a little confused about what code you're actually running now. If what I just posted doesn't help post a quick snippet of the code you're currently running that's working for jobs with 1 VM and we'll go from there, but the simple -join should be all you need.
That is awesome code and did the trick for my multi-VM jobs to list out all the servers. Thanks so much for the help. :)
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

tsightler
VP, Product Management
Posts: 5399
Liked: 2229 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 04, 2015 7:08 pm

Awesome! Glad it worked.

chris.childerhose
Service Provider
Posts: 107
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 04, 2015 9:46 pm

Now I am having a similar issue with the Repository lines of the script. I added the following -

$jobOptions | Add-Member -MemberType NoteProperty -Name "Repository" -value ($repo -join ",")

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 just want it to list the repository per job versus per server by the looks of it. Then I would not require the JOIN action.

Any thoughts?
-----------------------
Chris Childerhose
Veeam Vanguard / VMCE v9
VCAP-DCA / VCP6 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests