Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Returning -ErrorVariable defined in remote session invoked with invoke-command

$
0
0

Hi fellow PowerShellers,

I'm trying to find a solution on how to get error variables defined in remote sessions, back to the local session. Let's say I do:

Invoke-command -ComputerName testServer -Scriptblock {

Get-process -Name svchost -errorvariable cmdExecutionStatus

}

I would like to send the cmdExecutionStatus variable back to the local session. I have tried various stuff like:

- assigning the entire invoke-command to a variable, but that of course only gives me the objects returned from the cmdlet inside the scriptblock, in a deserialized form

- setting $lastexitcode = cmdExecutionStatus and then calling the remote server again to assign a new variable to $lastExitCode

- searched the interwebs in general, this page is great btw - http://powershell.com/cs/media/p/7257.aspx :-D

// Do anyone know how, or if it is possible at all, to get an errorvariable defined in a remote session, back to the local session?

Thank you in advance.


Red Baron


Viewing all articles
Browse latest Browse all 21975

Trending Articles