Home > database >  How can I declare a variable ($output) with the output within an IF -Statement?
How can I declare a variable ($output) with the output within an IF -Statement?

Time:02-08

My goal is to fill the variable $output with the, you guessed it, output of the PSService.exe. Unfortunately this does not work. At all. As you can see in the code, I'm looking for a specific line, which is needed to tell if the command was a success or not.

Get-Content .\Computer.txt | ForEach-Object {
            $var = $_.Split(“ ”)
}

foreach ($pc in $var) {
            .\PSService.exe \\$pc start WinRM
            $output = <command> 
            If ($output –like “START_PENDING”){
                        Write-Host “Success $pc”
            } else {
                        Write-Host “Error $pc”
            }
}

How can I declare a variable ($output) with the output within an IF -Statement?

CodePudding user response:

$output = .\PSService.exe \\$pc start WinRM

This one does the job.

  •  Tags:  
  • Related