# retrive variable value inside ps1 script

**URL:** <https://forums.powershell.org/t/retrive-variable-value-inside-ps1-script/4968>\
**Category:** PowerShell Help\
**Created:** [October 4, 2015, 9:38pm UTC](https://forums.powershell.org/t/retrive-variable-value-inside-ps1-script/4968 "2015-10-04T21:38:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![farid-baraka](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@farid-baraka](https://forums.powershell.org/u/farid-baraka)\
**Post date:** [October 4, 2015, 9:38pm UTC](https://forums.powershell.org/t/retrive-variable-value-inside-ps1-script/4968/1 "2015-10-04T21:38:07Z")

</div>

hello:  
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

---

<div class="post-metadata">

**Author:** ![aaron-miller](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@aaron-miller](https://forums.powershell.org/u/aaron-miller)\
**Post date:** [October 5, 2015, 12:05am UTC](https://forums.powershell.org/t/retrive-variable-value-inside-ps1-script/4968/2 "2015-10-05T00:05:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [October 5, 2015, 12:59am UTC](https://forums.powershell.org/t/retrive-variable-value-inside-ps1-script/4968/3 "2015-10-05T00:59:11Z")

</div>

After you pass -ArgumentList $myIP, you need to reference it in your function as $using:myIP. See [about\_Remote\_Variables](https://technet.microsoft.com/en-us/library/jj149005.aspx)

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

---

<div class="post-metadata">

**Author:** ![farid-baraka](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@farid-baraka](https://forums.powershell.org/u/farid-baraka)\
**Post date:** [October 5, 2015, 9:08pm UTC](https://forums.powershell.org/t/retrive-variable-value-inside-ps1-script/4968/4 "2015-10-05T21:08:18Z")

</div>

thank you

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:44pm UTC](https://forums.powershell.org/t/retrive-variable-value-inside-ps1-script/4968/5 "2024-05-16T20:44:44Z")

</div>


