Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Issue with Enter-PSSession when running from the shell and via script

$
0
0

Hello

Can someone please help me with the following issue

If I open the PowerShell console and do the following

Enter-PSSession -computername Server1
"This is a test" > C:\Log.txt
Exit-PSSession

It works e.g. the Log.txt file is create as expected on Server1

However if I put the exact same command in a script and execute the script.

./TestScript.ps1

The Log.txt file is created on my Client (e.g. PC) and not the Server1

I also tried using $Session = New-PSSession -ComputerName Server1 etc.....

then Enter-PSSession -Session $Session

I also tried Enter-PSSession etc....
Start-Sleep -seconds 60
"This is a test" > C:\Log.txt
Exit-PSSession

Again no luck when running from shell all OK, then executing as a script (again from the command line) files is created on client

Any ideas why this is happening please and how to resolve, I am using PowerShell v4 on the client and PowerShell v2 on the Server

Thanks

AAnotherUser__


AAnotherUser__


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>