function - Passing a [ref] parameter in a remote session in Powershell -


i have powershell question.

i trying value function variable, calling function reference variable. example:

$var = new.object system.object; example-function -outobject ([ref]$var); 

where example-function defined this:

function example-function {     [cmdletbinding()]     param     (         [parameter(mandatory=$true)]         [ref]         $outobject     )     $somevalue = ...     #write output     #do something...      $outobject.value = $somevalue; } 

this working ok. $var variable gets it's value function ($somevalue).

but, not working when example-function imported remote session, example:

$creds = new-object system.management.automation.pscredential('user','pass') $session = new-pssession -computername 'examplecomputer' -credential $creds -authentication credssp  import-pssession -session $session -commandname 'example-function' -allowclobber  $var = new.object system.object; example-function -outobject ([ref]$var); 

this code throwing following error: cannot process argument transformation on parameter 'outobject'. reference type expected in argument.

i assuming becuase example-function running on other computer ('examplecomputer'), while ([ref]$var) referencing variable in memory of computer running scripts (my computer). reason don't want (cannot) use return statement way becuase function writing output, , in powershell, outputed function returned. so, question is, can value function has lot of output variable, when function running in remote session? if cannot done using [ref] parameter, there way?

thanks

okay lets try again:

invoke-command returns whatever run in remote pipeline. means can do:

$var = invoke-command -session $session -command {example-function} 

which saves in $var variable. can filter results , whatever information need.

and please remember [ref] makes more complicated is.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -