2017-03-16 87 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

相关问题