PS Remoting

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

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

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