# PS Remoting

**URL:** <https://forums.powershell.org/t/ps-remoting/9216>\
**Category:** PowerShell Help\
**Created:** [August 22, 2017, 5:15am UTC](https://forums.powershell.org/t/ps-remoting/9216 "2017-08-22T05:15:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![syn3rgy](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@syn3rgy](https://forums.powershell.org/u/syn3rgy)\
**Post date:** [August 22, 2017, 5:15am UTC](https://forums.powershell.org/t/ps-remoting/9216/1 "2017-08-22T05:15:54Z")

</div>

Hi All,

Wondering if someone may be able to point to me where I am going wrong. I am trying to update Trend remotely however, when i run the script, it seems to only update Trend on the local machine in which i am running it and not on the remote machines as well.

Thank you

```
#Credentians for remote sessions
$Cred = "USERNAME" 

#Path To Trend
    $TrendPath = "c:\" ;cd "C:\Program Files (x86)\Trend Micro\OfficeScan Client"

#Update Command
    $update = ./pccntmon -u

#Creating Remote PS Session on Servers
  $RemoteServersSessions = New-PSSession -computername '10.2.34.34','10.2.34.35' -Credential $Cred

    
    Write-Warning "Open Remote PS Sessions" 
# $RemoteServersSessions

# Invoking Remote Command to change path and update trend
    Invoke-Command -Session $RemoteServersSessions -ScriptBlock{$TrendPath; $update}

    Write-Warning "Trend on servers should now be updated"
    Write-Warning "Disconnecting remote Sessions"

#Disconnect PS remote sessions
    Disconnect-PSSession -Session $RemoteServersSessions
```

---

<div class="post-metadata">

**Author:** ![micheal100](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/micheal100/32/438_2.png) [@micheal100](https://forums.powershell.org/u/micheal100)\
**Post date:** [August 22, 2017, 5:48am UTC](https://forums.powershell.org/t/ps-remoting/9216/2 "2017-08-22T05:48:22Z")

</div>

I think it’s because the $trendpath and $update variables only exist in a local context, not on the remote machine. You can just pass those in as variables though, see the following for an example [http://windowsitpro.com/powershell/using-variables-remote-powershell-sessions](http://windowsitpro.com/powershell/using-variables-remote-powershell-sessions)

---

<div class="post-metadata">

**Author:** ![syn3rgy](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@syn3rgy](https://forums.powershell.org/u/syn3rgy)\
**Post date:** [August 22, 2017, 6:37am UTC](https://forums.powershell.org/t/ps-remoting/9216/3 "2017-08-22T06:37:17Z")

</div>

Hi Michael,

I think you may be right. I see in Powershell v3 you can use “$using:BLA” however, I am not quite sure on how to incorporate that

Snippet:

```
Invoke-Command -Session $RemoteServersSessions -ScriptBlock {$Using:TrendPath; $Using:update}
```

Full Script:

```
#Credentians for remote sessions
$Cred = "TEN\M0171512" 

#Path To Trend
    $TrendPath = "c:\" ;cd "C:\Program Files (x86)\Trend Micro\OfficeScan Client"

#Update Command
    $update = ./pccntmon -u
 
#Creating Remote PS Session on Servers
  $RemoteServersSessions = New-PSSession -computername '10.2.34.34','10.2.34.35' -Credential $Cred
    
    Write-Warning "Open Remote PS Sessions" 
          $RemoteServersSessions

# Invoking Remote Command to change path and update trend
    #Invoke-Command -Session $RemoteServersSessions -ScriptBlock{$TrendPath; $update}
    Invoke-Command -Session $RemoteServersSessions -ScriptBlock {$Using:TrendPath; $Using:update}

    Write-Warning "Trend on servers should now be updated"
    Write-Warning "Disconnecting remote Sessions"

#Disconnect PS remote sessions
    Disconnect-PSSession -Session $RemoteServersSessions
```

---

<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:37pm UTC](https://forums.powershell.org/t/ps-remoting/9216/4 "2024-05-16T20:37:42Z")

</div>

Closed on May 16, 2024, 8:37pm UTC


