Coming from Linux, I'm trying to automate the gathering of Veeam Backup jobs with a PowerShell script.
I started to see how PowerShell arrays work, then I tried with a small test:
$users = 'mark','josh','stephen'
$city = 'seattle','boston','chicago'
for ($i = 0; $i -lt $users.Count; $i++) {
Write-Host $users[$i] 'live in' $city[$i]
}
Output:
mark live in seattle josh live in boston stephen live in chicago
But when I modify my 2 arrays adding command instead of strings:
$jobname = @(gwmi -Namespace "root/veeambs" -Class "job" | select typetostring, name | ft -HideTableHeaders | Out-String)
$isenabled = @(gwmi -Namespace "root/veeambs" -Class "job" | select typetostring, scheduleenabled | ft -HideTableHeaders | Out-String)
for ($i = 0; $i -lt $jobname.Count; $i++) {
echo $jobname[$i] ' --> ' $isenabled[$i]
}
Output is:
Job1 Job2 Job3 Job4 Job5 Job6 Job7 Job8 Job9 Job10 Job11 Job12 Job13 Job14 JOb15 Job16 Job17 Job18 Job19 Job20 --> False True True False True True False True True True True True True True True True True True True True
instead of:
Job1 --> False Job2 --> True Job3 --> True Job4 --> False etc.
Running the entire command manually I get:
PS> gwmi -Namespace "root/veeambs" -Class "job" | select typetostring, name, scheduleenabled typetostring name scheduleenabled ------------ ---- --------------- Job1 False Job2 True Job3 True Job4 False Job5 True Job6 True Job7 False Job8 True Job9 True Job10 True Job11 True Job12 True Job13 True Job14 True Job15 True Job16 True Job17 True Job18 True Job19 True Job20 True
I'm probably doing something wrong!