Upload File to SharePoint using Web Services and PowerShell

Requirement: For a file upload issue troubleshooting, had to call SharePoint web services to upload a file into SharePoint document library.

Upload File to SharePoint Library using Web Services – PowerShell

Here is my PowerShell script to upload file to SharePoint document library using web services:

$SourceFile = "D:\Reports\MonthlyRpt-Jan14.csv"
$DestinationPath ="https://operations.crescent.com/Reports/MonthlyRpt-Jan14.csv" 

$WebServiceURL = "https://operations.crescent.com/_vti_bin/copy.asmx?WSDL" 
$CopyWebService = new-WebServiceProxy -Uri $WebServiceURL  -UseDefaultCredential

#For custom Credentials, use:
#$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($UserName,$SecurePasssword)
#$UserName = "Domain\UserName"
#$Password = "PASSWORD"
#$SecurePasssword = ConvertTo-SecureString -String $Password -AsPlainText -Force
#$CopyWebService= new-WebServiceProxy -Uri $WebServiceURL -Credential $cred 

#Get the File from Disk
$FileData = [System.IO.File]::ReadAllBytes($SourceFile)    
#Get Filename
$FileName = [System.IO.Path]::GetFileName($SourceFile).ToString()

$Metadata = @() 

$results = $null
#Upload file to SharePoint library using Web Service
$ret= $CopyWebService.CopyIntoItems($FileName, $DestinationPath, $Metadata, $FileData, [ref]$results)

Write-host "Upload Status:" $results[0].ErrorCode

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

2 thoughts on “Upload File to SharePoint using Web Services and PowerShell

  • anything for Sharepoint sites that are https and use ADFS

    Reply
  • Great!!! It worked.Thanks a lot.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *