PowerShell script exchange
Post Reply
dsATspace
Influencer
Posts: 19
Liked: never
Joined: Feb 28, 2022 9:09 am
Full Name: dennis
Contact:

How to get/use JobName in a array ? | Get-VBRJob | Get-VBRJobObject

Post by dsATspace »

Hello,

I like to get a List of BackupJobs with: Get-VBRJob -Name * to show the VM-Names ( in my Case: VM1 & VM2 )
to use it with: Get-VBRJobObject
So my wish is to have this output:

VM1
VM2



Get-VBRJob -Name *

Job Name Type State Last Result Description
-------- ---- ----- ----------- -----------
VM1_JOB VMware Backup Stopped Success Created by WIN-QLOUAP15J4L\Administrator at 28.02.2022 13:27.
VM2_JOB VMware Backup Stopped Success Created by WIN-QLOUAP15J4L\Administrator at 28.02.2022 14:11.


Get-VBRJobObject -Job VM2_JOB

Name Type ApproxSize Location
---- ---- ---------- --------
VM2 Include 16 GB 192.168.11.220\server...



Code: Select all

$jobarray = Get-VBRJob -Name *
foreach ($job in $jobarray)
{

$JobName = $job
$JobObject = Get-VBRJob -name $JobName
$Objects = $JobObject.GetObjectsInJob()
$Objects.name

}
did not work

Error Messages:

Code: Select all

Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat.
In Zeile:6 Zeichen:1
+ $Objects = $JobObject.GetObjectsInJob()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

VM2
Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat.
In Zeile:6 Zeichen:1
+ $Objects = $JobObject.GetObjectsInJob()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

VM2
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: How to get/use JobName in a array ? | Get-VBRJob | Get-VBRJobObject

Post by oleg.feoktistov »

Hi Dennis,

Please have a closer look at what the script is writing to $JobName and what Get-VBRJob -name <string> is accepting.
Also, I don't know why do you need to use Get-VBRJob cmdlet twice here. Try this instead:

Code: Select all

$jobarray = Get-VBRJob
foreach ($job in $jobarray)
{

$JobObject = Get-VBRJobObject -Job $job
$JobObject.name

}
Thanks,
Oleg
chris.arceneaux
VeeaMVP
Posts: 695
Liked: 374 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: How to get/use JobName in a array ? | Get-VBRJob | Get-VBRJobObject

Post by chris.arceneaux »

Hi Dennis,

You've got a few things going on here. First off, the answer to your question in the thread title:

How to get/use JobName in a array?

Image

Key thing to note is the column title in PowerShell doesn't always match the actual parameter name. A quick PS trick to identify the actual parameter name is this:

Image

On to your actual request:

I like to get a List of BackupJobs with: Get-VBRJob -Name * to show the VM-Names

The Get-VBRJobObject cmdlet returns the items explicitly listed in the job configuration.

For example, here's my job configuration:

Image

Here's what Get-VBRJobObject returns:

Image

As I defined VM folders (versus specifying each and every VM) to be backed up, I won't be able to see the VM names using Get-VBRJobObject. Here's sample code to do that:

Code: Select all

$jobs = Get-VBRJob
foreach ($job in $jobs){
    $backup = $job.FindLastBackup()
    $objects = $backup.GetObjects()
    $objects | Select-Object @{n='Job Name';e={$job.Name}}, Name, Type
}
Note that I didn't specify a job name so all jobs were returned. Here's sample output of this code:

Image

Hope this helps!
dsATspace
Influencer
Posts: 19
Liked: never
Joined: Feb 28, 2022 9:09 am
Full Name: dennis
Contact:

Re: How to get/use JobName in a array ? | Get-VBRJob | Get-VBRJobObject

Post by dsATspace »

Hi Chris,
thanks a lot!

have a nice weekend!

Code: Select all

$jobarray = Get-VBRJob
foreach ($job in $jobarray)
{

$vm=Get-VBRJobObject -Job $job.name
$vm.name

}
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 9 guests