-
- Novice
- Posts: 3
- Liked: never
- Joined: Mar 27, 2020 10:47 pm
- Full Name: Jim Pyle
- Contact:
looping get-vbrjob
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
}
Is there another way to accomplish this result?
$jobs = get-content joblist.txt
foreach($job in jobs){
$jobname = get-vbrjob -name "$job"
$jobname.name
}
-
- Veeam Software
- Posts: 2010
- Liked: 670 times
- Joined: Sep 25, 2019 10:32 am
- Full Name: Oleg Feoktistov
- Contact:
Re: looping get-vbrjob
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
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
-
- Novice
- Posts: 3
- Liked: never
- Joined: Mar 27, 2020 10:47 pm
- Full Name: Jim Pyle
- Contact:
Re: looping get-vbrjob
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
}
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
}
-
- Novice
- Posts: 3
- Liked: never
- Joined: Mar 27, 2020 10:47 pm
- Full Name: Jim Pyle
- Contact:
Re: looping get-vbrjob
typo:
When I pass it 1 job name in the console with a WITHOUT a loop it works.
When I pass it 1 job name in the console with a WITHOUT a loop it works.
-
- 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
Hi Jim,
Below is working sample code to point you in the right direction:
jobs.txt contents:
PowerShell code:
Output of code above:
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
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
}
Who is online
Users browsing this forum: No registered users and 9 guests