Script doesn't work in Remote Session (Enter-PSSession)

Nov 19, 2012 at 2:43 PM


The Script is working fine when I'm using it in a local session. But we need to use it in a remote Session (Enter-PSSession), and there I'm always receving following error:

Copying rtest.txt to rtest.txt in IT Testbereich ...
The script has stopped because there has been an error.

Is there any possibility to get this work with a Remote Session?

Here are the steps I'm doing on the remote Server:
Enter-PSSession -ComputerName SHAREPOINTSERVER
Add-PSSnapin Microsoft.SharePoint.PowerShell
. C:\temp\Get-SPScripts.Copy-FilesToSP.ps1
Copy-FilestoSP -LocalPath "C:\temp\test\" -SiteUrl "http://apy-shp-01/sites/Teams/test" -Library "Documents"

Feb 1, 2013 at 11:02 AM

Am also experiencing the same error as above after running the commands Enter-PSSession and Add-PSSnaping.

Copy-FilestoSp -LocalPath "C:\CopyDir" -SiteUrl "http://server/" -Library "Registry" -ManifestFilePath "C:\ManifestFiles\Manifest.xml" -Overwrite

Any clarification or update would be very much appreciated. Nice tool..

Oct 1, 2013 at 3:25 PM
I got it working in a remote session. I pretty much had to run it line by line to see what was breaking. Some things I had to do: Create an encrypted text file to store Sharepoint credentials. Run the Enable-WSManCredSSP command on both the server and the client. Then on the client run gpedit.msc to allow delegation of credentials. On server run Enable -PSRemoting

Then I use these commands to call the script:

$SecurePassword = get-content $SecureStringFilePath | convertto-securestring -key (1..16)
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword
$s = New-PSSession -ComputerName $Server -credential $Credentials -Authentication CredSSP
Invoke-Command -Session $s -File "Copy-FilestoSP.ps1" -Argumentlist $ImportPath, $SiteUrl, $Library, $LogFile
Remove-PSSession $s