0
votes

this question is not just about using PowerShell to upload document, but focus on "remote".

I have 2 servers now,

  1. one SharePoint farm server
  2. one task server dedicated to run script against SharePoint farm remotely.

We're using CredSSP to do authentication and until now all tasks working well, like manipulating List/Item. but upload document is a blocker here.

The file to be uploaded is at SharePoint server locally.

The script block inside invoke-command works well if I directly run it inside SharePoint server

used script:

$credsspSession=New-PSSession -cn $SPServer-Authentication Credssp -Credential $credentail
icm -session $credsspSession {
    Add-PSSnapin "Microsoft.sharepoint.powershell"
    $spweb=Get-SPWeb "https://siteURL"
    $file=Get-Item "filename"
    $spFolder=$spweb.GetFolder("FolderName")
    $fileCollection=$spFolder.Files
    $fileCollection.Add("FolderName/file.name",$file.OpenRead(),$false)

}

the error messgae reported:

PSMessageDetails      : 
Exception             : System.Management.Automation.MethodInvocationException: Exception calling "Add" with "3" argument(s): "" ---> Microsoft.SharePoint.SPException
                           at Microsoft.SharePoint.SPFileCollection.Add(String urlOfFile, Stream file, Boolean overwrite, String checkInComment, Boolean checkRequiredFields)
                           at Microsoft.SharePoint.SPFileCollection.Add(String urlOfFile, Stream file, Boolean overwrite)
                           at CallSite.Target(Closure , CallSite , Object , String , Object , Boolean )
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
                           at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject          : 
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : SPException
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 9
PipelineIterationInfo : {}
PSComputerName        : fe0vm1074
RunspaceId            : 3ca5166e-c28d-4dc5-a9f6-0d31091106f4

Any idea about this? thank you for any tip.

1
the file to be uploaded is at SharePoint server locallyaZh
the script block inside invoke-command works well if I directly run it inside SharePoint serveraZh

1 Answers

0
votes

As a result, this is identified as a "Symantec" issue, it's blocking my remote powershell to upload document. After installation of "Symantec Patch"(provided by Symantec, installed by my colleague), issue resolved.