PowerShell script exchange
Post Reply
reber2020
Novice
Posts: 3
Liked: never
Joined: Mar 27, 2020 10:47 pm
Full Name: Jim Pyle
Contact:

looping get-vbrjob

Post by reber2020 »

Why is get-vbrjob -name, not working in this simple script. Im tring to pull some info from job listed in a txt file. In this example I want to display the name of each jobname from a list in a text file. I want to pull various objects from the job, but it does not want to take the get-vbrjob -name variable from the text file.

Is there another way to accomplish this result?

$jobs = get-content joblist.txt
foreach($job in jobs){
$jobname = get-vbrjob -name "$job"

$jobname.name

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

Re: looping get-vbrjob

Post by oleg.feoktistov »

Hi Jim,

Just to be sure, did you happen to put jobs instead of $jobs in your loop declaration by mistake?
Further, make sure to have job names in your txt file not wrapped in quotes as get-content cmdlet
recognizes each member of an array parsed in a file as a string already, no need to have them quoted. If names are in quotes,
you'll just have null output.

Other than that, should work fine.

Thanks and take care,
Oleg
reber2020
Novice
Posts: 3
Liked: never
Joined: Mar 27, 2020 10:47 pm
Full Name: Jim Pyle
Contact:

Re: looping get-vbrjob

Post by reber2020 »

Hi Oleg,

Thank you for the reply, the job names in the txt file are not wrapped in quotes. I just tried to rerun this exactly as below. It gives no errors so leads me to believe it is doing something but not sending anything out to the console. Any other ideas on how to troubleshoot this problem. Could it be a issue that it needs the full path to the get-vbrjob command in the script. When I pass it 1 job name in the console with a loop it works.

add-pssnapin veeampssnapin
$jobs = get-content us19_jobs1.txt

foreach($job in $jobs){
get-vbrjob -name $job
}
reber2020
Novice
Posts: 3
Liked: never
Joined: Mar 27, 2020 10:47 pm
Full Name: Jim Pyle
Contact:

Re: looping get-vbrjob

Post by reber2020 »

typo:
When I pass it 1 job name in the console with a WITHOUT a loop it works.
chris.arceneaux
VeeaMVP
Posts: 695
Liked: 374 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: looping get-vbrjob

Post by chris.arceneaux »

Hi Jim,

Below is working sample code to point you in the right direction:

jobs.txt contents:

Code: Select all

vmware
veeam
saml_Org Backup
misc
storage
active_directory
database
pki
veeam-sp
gitlab
backup_Org Backup
Copy to Cloud Connect
templates
PowerShell code:

Code: Select all

Add-PSSnapin veeampssnapin
$file = Get-Content jobs.txt
$jobs = Get-VBRJob

foreach($job in $file){
    # Matching up job name to Backup Job
    $vbrJob = $jobs | Where-Object {$_.Name -eq "$job"}
    $vbrJob.Name
}
Output of code above:

Image
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests