Author Posts

October 5, 2015 at 3:08 am

i have a script that run from a source computer:
$myip = read-host "enter remote ip"
# file on remote computer
function test {
& 'c:\test\test.ps1'
Invoke-Command -ComputerName $myip -scriptblock ${function:test} -ArgumentList $myip

#on remote computer i have c:\test\test.ps1 with these lines
param ($ip)
Write-Host "you are on:$ip"
#do task

the problem is that i cannot retrieve $ip, the result on my source station is:
you are on:

thank you

October 5, 2015 at 5:35 am

I'm sure you'll get much more elegant answers, but you could always have the remote pc write to file, and the source get-content that file then delete it, or something similar.

October 5, 2015 at 6:29 am

After you pass -ArgumentList $myIP, you need to reference it in your function as $using:myIP. See about_Remote_Variables

Additionally, there is a free eBook under Resource "Secrets of Remoting" that would provide examples for you.