3

I am trying to find all last job statuses fro a list of VMs backed up with veeam backup. Strangely the loop do not go to the next vm. Here is what I do:

Add-PSSnapin VeeamPSSnapin
$VMlist = "vm1, vm2" 
$VMlist = $VMlist.split(",");
Foreach ($i in $VMlist) {

    foreach($Job in (Get-VBRJob))
{
        $Session = $Job.FindLastSession()
        if(!$Session){continue;}
        $Tasks = $Session.GetTaskSessions()
        $Tasks | ?{$_.Name -eq $VMlist} | %{write-host $_.Name ":" $_.Status}

It seems I have a problem in the for each loop, since it stuck and I do not get any output. What is thebest way to iterate over the slit of VMs?

Thanks in advance!

0

1 Answer 1

2

You're looking for the $VMList array in $Tasks not the individual VM $i, just change: {$_.Name -eq $i}

Also your VM names will include leading spaces, either remove the spaces from your input string "vm1,vm2", or use Trim() after Split()

Add-PSSnapin VeeamPSSnapin
$VMlist = "vm1,vm2" 
$VMlist = $VMlist.split(",");
foreach ($i in $VMlist) {
    foreach ($Job in (Get-VBRJob)) {
        $Session = $Job.FindLastSession()
        if (!$Session) {continue; }
        $Tasks = $Session.GetTaskSessions()
        $Tasks | Where-Object {$_.Name -eq $i} | ForEach-Object {Write-Host $_.Name ":" $_.Status}
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.