Web Hizmetlerini ve PowerShell'i kullanarak Dosyayı SharePoint'e Yükleme


Gereksinim: Bir dosya yükleme sorununun giderilmesi için, SharePoint belge kitaplığına bir dosya yüklemek üzere SharePoint web hizmetlerini aramanız gerekiyordu.

Web Hizmetleri - PowerShell'i kullanarak Dosyayı SharePoint Kitaplığına Yükleme

Web hizmetlerini kullanarak SharePoint belge kitaplığına dosya yüklemek için kullandığım PowerShell betiğim:


$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

İlgili makaleler