将SharePoint Online Client组件(Microsoft.SharePoint.Client)与powershell 2.0一起使用

问题描述 投票:1回答:1

我正在尝试使用PowerShell在SharePoint列表中创建数据。我已准备好脚本,适用于PowerShell 3.0和PowerShell 4.0。但是当我尝试使用PowerShell 2.0运行脚本时,它无法加载标题中提到的程序集,并在脚本执行开始时抛出错误。

无法加载文件或程序集'path \ Microsoft.SharePoint.Client.dll'或其依赖项之一。此程序集由比当前加载的运行时更新的运行时构建,无法加载。

是否可以在不升级到PowerShell 3或4的情况下使用PowerShell 2.0实现目标?

powershell sharepoint powershell-v2.0 sharepoint-online
1个回答
2
投票

简短的回答,没有。

PowerShell 2.0是使用.NET 2.0构建的,它无法加载使用.NET 4.0构建的DLL

这里有更多的例外描述:BadImageFormatException

例外情况就是这样,但这里有一些关于PowerShell要求的文档:Windows PowerShell System Requirements

要对SharePoint Online进行身份验证,几乎在每个代码示例中都使用了SharePointOnlineCredentials类,它是Microsoft.SharePoint.Client的一部分,即.NET 4。

但是,可以使用令牌对SharePoint Online REST API进行身份验证。这里有一些来自stackexchange的信息:How to authenticate to SharePoint Online (Office 365) using REST API

最后一个选项是使用直接用户名\密码和联合身份验证。如果有一个相应的JAVA库,我也不熟悉,我只能在这里给你一个nodejs的例子。简而言之,您需要将预先配置的SAML XML POST到MS Online Security Token Service(STS),接收编码令牌并将其与SharePoint Online交换到auth cookie。您可以使用fiddler查看实际请求。

nodejs代码示例:OnlineUserCredentials.ts

关于令牌:SharePoint Online (O365) OAuth Authentication | Authorizing REST API calls against SharePoint Online Site | Get Access token from SharePoint Online | Set up OAuth for SharePoint Online Office 365

© www.soinside.com 2019 - 2024. All rights reserved.