I'm trying to use Invoke-Command to run a command in PowerShell remotely on a number of machines, and capture their output from it, but I'm not getting any output from it. I suspect it's from how I'm using Start-Process, but I'm not sure.
$RunCommand = {
Start-Process "$env:ProgramFiles\Some Program\someprogram.exe" -ArgumentList "-SignatureUpdate"
}
$comp_list = @(Get-Content "c:\temp\comp_list.txt")
$cred = Get-Credential
$jobs = Invoke-Command -Credential $cred -Computer $comp_list -ScriptBlock $RunCommand -AsJob
Wait-Job $jobs
$r = Receive-Job $jobs
$r | % { $_ > c:\temp\$($_.PScomputerName).output }
Is there a better way to invoke a command using environment variables like that?
Invoke-Command -ComputerNamenot just-computer-Computeris an alias for-ComputerName, so either will work just fine.$ExecutionContext.InvokeCommand.NewScriptBlock()to create the script block. I've used this with Invoke-Ssh command