不在 Sharepoint 服务器上时的 Powershell Sharepoint 管理单元

Powershell Sharepoint snapin when not on the sharepoint server

我是 powershell 和 sharepoint 的新手,我需要编写脚本来自动删除附件并将其从 outlook 上传到 sharepoint。我已经轻松完成了提取附件的第一部分,但是上传到 Sharepoint 已变得很难按照我公司的规则进行。据我了解,要使用 sharepoint cmdlet,您需要添加 sharepoint 管理单元,但我无法这样做,因为我无权访问 sharepoint 服务器。有没有不在服务器上的管理单元,如果没有,我可以用其他方式上传吗?

除非服务器是 SP 服务器,否则无法添加 SP 管理单元。相反,使用 webservice/webclient 方法上传文件。像这样的东西应该取决于你的 SP 版本: http://blog.sharepoint-voodoo.net/?p=205

已接受的答案 link 已损坏。

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. 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

$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