Monday, February 3, 2014

Upload File to SharePoint using Web Services and PowerShell

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

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

$WebServiceURL = "http://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



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...