How do I pass a local variable to remote PowerShell Script -


let me brief out methods tried.

here start_testtalk.ps1 script

$rn = $env:rname $testv = "local_variable" write-host $testv write-host $rname write-host $rn write-host $env:rname

i've declared below variables

$name="myname" $cpu= 100

first method:

ps c:\users\administrator> invoke-command -session $s -scriptblock{ & "c:\users\administrator\desktop\start_testtalk.ps1 " -rname $args[0] -rcpu $args[1]}-argumentlist $name,$cpu local_variable

second method

ps c:\users\administrator> invoke-command -session $s -scriptblock{ & "c:\users\administrator\desktop\start_testtalk.ps1 " -rname $using:name -rcpu $using:cpu} local_variable

third method

ps c:\users\administrator> invoke-command -session $s -scriptblock{ param($name, $cpu) & "c:\users\administrator\desktop \start_testtalk.ps1" -rname $name -rcpu $cpu}-argumentlist $name ,$cpu local_variable

all above 3 methods prints 'local_variable' local remote machine , doesn't print variable pass local machine(here $name).

you can use :using variable prefix:

invoke-command -session $s -scriptblock{ & "c:\users\administrator\desktop\test.ps1" -rname $using:name -rcpu $using:cpu} 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -