retrive variable value inside ps1 script

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

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.

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.

thank you