【发布时间】:2019-12-17 14:55:58
【问题描述】:
我正在尝试连接到共享点环境,并且我想使用 Powershell 版本 6 进行连接。为什么?最终,我想将 PS 命令放入 .net core 3 应用程序中。据我所知,我不能在 .net core 中使用 PS5.1。
关于这个 powershell 脚本:
Import-Module -Force -name Microsoft.Online.SharePoint.PowerShell;
Import-Module -Force -name Microsoft.Online.SharePoint.PowerShell -DisableNameChecking;
$username = 'admin@shootme.com';
$password = 'right now';
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force);
Connect-SPOService -Url https://shootme.sharepoint.com -Credential $cred;
当我在默认的 PS 5.1 中尝试此操作时,它运行良好。当我在 PS 6.2.3 上尝试此操作时,出现错误:
Connect-SPOService : The remote server returned an error: (400) Bad Request.
At line:1 char:1
+ Connect-SPOService -Url https://shootme.sharepoint.com -Credent ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-SPOService], WebException
+ FullyQualifiedErrorId : System.Net.WebException,Microsoft.Online.SharePoint.PowerShell.ConnectSPOService
较新的 Powershell 是否有不同的语法或者我做错了什么? 另外,在 .net core 中运行脚本时,也许有一种方法可以在 ps 5.1 中运行脚本?
【问题讨论】:
-
您可能需要查看该模块所需的库与 PowerShell Core 的兼容性。我的猜测是在内部异常中,该 cmdlet 需要一些东西才能像你在 PowerShell 的桌面版本中所期望的那样运行。
-
@Ash 也许是这样,但文档真的很糟糕。不知道微软想要什么 ps 6。
-
如果您使用 C#,您可以针对 .Net Standard 并使用 Sharepoint libraries 创建您自己的 cmdlet。
-
@Ash 我不确定如何针对 .Net Standard(现在针对 .net core 3.1),但实际上我已经尝试过该解决方案:我得到了完全相同的错误。 (400) 错误请求。我认为这与此有关:sharepoint.uservoice.com/forums/329220-sharepoint-dev-platform/…(目前没有对 CSOM 库的 .net 核心支持)
-
如果您创建一个 .NET Standard 应用程序,然后将其更改为针对 .NET Framework 的兼容版本,例如 4.7.2,您可以使用较旧的库 - docs.microsoft.com/en-us/dotnet/standard/…
标签: powershell sharepoint .net-core powershell-6.0