简体   繁体   English

当不在共享点服务器上时,Powershell Sharepoint管理单元

[英]Powershell Sharepoint snapin when not on the sharepoint server

I am new to both powershell and sharepoint, and I need to make script to automate the removal and uploading of attachments from outlook to sharepoint. 我是PowerShell和Sharepoint的新手,我需要编写脚本以自动执行从Outlook到Sharepoint的附件删除和上传。 I have easily completed the first part of extracting the attachment, however the uploading to sharepoint has become difficult do to my company's rules. 我已经轻松完成了提取附件的第一部分,但是,将文件上传到Sharepoint变得很难遵守我公司的规则。 As I understand to use sharepoint cmdlets you need to add the sharepoint snap-in but I am unable to do so because I dont have access to the sharepoint server. 据我了解,使用共享点cmdlet需要添加共享点管理单元,但由于无法访问共享点服务器,因此无法执行此操作。 Is there anyway to the snapin without being on the server and if not can I upload it another way? 无论如何,管理单元都没有管理单元,如果没有,我可以用其他方式上传它吗?

You can't add the SP snap in unless the server is a SP server. 除非服务器是SP服务器,否则无法添加SP管理单元。 Instead, use a webservice/webclient approach to upload the file. 而是使用webservice / webclient方法上载文件。 Something like this should work depending on your SP version: http://blog.sharepoint-voodoo.net/?p=205 取决于您的SP版本,类似的东西应该可以工作: http : //blog.sharepoint-voodoo.net/?p=205

Accepted answer link is broken. 接受的答案链接已损坏。

This script uses PowerShell to upload a file to a document library in SharePoint using purely web service calls so it could be done remotely, also meaning it should work with O365 though I have not tried. 该脚本使用PowerShell通过纯Web服务调用将文件上传到SharePoint中的文档库,因此可以远程完成,这也意味着它应该可以与O365一起使用,尽管我没有尝试过。 These variables are used throughout the script for source file, destination file and authentication. 这些变量在整个脚本中都用于源文件,目标文件和身份验证。 If your workstation is on the same domain as SharePoint, and your logged on user has permissions to the SharePoint site, you can omit $username, $password, and $domain 如果您的工作站与SharePoint在同一域中,并且您登录的用户具有访问SharePoint网站的权限,则可以省略$ username,$ password和$ domain

$LocalPath = "C:\filename.docx"
$spDocLibPath = "http://site.contoso.com/sites/spteam/Shared Documents/"
$username = "someone"
$password = "somepassword"
$domain = "contoso"

$UploadFullPath = $spDocLibPath + $(split-path -leaf $LocalPath)
$WebClient = new-object System.Net.WebClient

if($username -eq "" -or $password -eq "" -or $password -eq "")
{ 
# Use Local Logged on User Credentials
$WebClient.Credentials = [System.Net.CredentialCache]::DefaultCredentials
}
else
{
# Alternate Login for specifying credentials
$WebClient.Credentials = new-object System.Net.NetworkCredential($username, $password, $domain)
}
$WebClient.UploadFile($UploadFullPath, "PUT", $LocalPath)

https://web.archive.org/web/20160404174527/http://blog.sharepoint-voodoo.net/?p=205 https://web.archive.org/web/20160404174527/http://blog.sharepoint-voodoo.net/?p=205

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM