2017-03-16 51 views
0

我試圖使用Powershell將文件上傳和簽入SharePoint Intranet站點。該腳本將在遠程機器上運行,而不是託管該站點的服務器。按照instructions given here上傳文件相對比較簡單。從遠程計算機上傳並簽入文件到SharePoint

下面是我用來上傳文件的一小部分流程。他們已成功上傳,但仍然向我查看。無論如何,使用Powershell檢查這些文件?

$destination = "http://mycompanysite.com/uploadhere/Docs」 
$File = get-childitem 「C:\Docs\stuff\To Upload.txt」 

# Upload the file 
$webclient = New-Object System.Net.WebClient 
$webclient.UseDefaultCredentials = $true 
$webclient.UploadFile($destination + "/" + $File.Name, "PUT", $File.FullName) 

不幸的是,使用SharePoint PowerShell模塊將不起作用,因爲它在遠程計算機上運行。

謝謝!

回答

1

您可能必須使用Microsoft.SharePoint.Client,而不是一個更簡單的時間,你可以從這裏下載:Download SharePoint Server 2013 Client Components

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" 
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" #loads sharepoint client runtime 
$destination = "http://mycompanysite.com/uploadhere" 
$listName = "Docs" 
$context = New-Object Microsoft.SharePoint.Client.ClientContext($destination) 
$context.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials #signs you in as the currently logged in user on the local host 
$context.RequestTimeout = 10000000 
$list = $context.Web.Lists.GetByTitle($listName) 
$context.Load($list) 
$context.ExecuteQuery() 

$stream = New-Object IO.FileStream($File.FullName,[System.IO.FileMode]::Open) 
$fileOptions = New-Object Microsoft.SharePoint.Client.FileCreationInformation 
$fileOptions.Overwrite = $true 
$fileOptions.ContentStream = $stream 
$fileOptions.URL = $File 
$upload = $list.RootFolder.Files.Add($fileOptions) 
$context.Load($upload) 
$context.ExecuteQuery() 

$upload.CheckIn("My check in message", [Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn) #other options can be looked at here: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.checkintype.aspx 
$context.ExecuteQuery() #finally save your checkin 
+0

對不起,不找回越快。這正是我最終使用的解決方案。出於某種原因使用REST/oData我一直遇到權限問題。 – Acie

相關問題