我正在尝试连接到共享点环境,并且我想使用 Powershell 版本 6 进行连接。为什么?最终,我想将 PS 命令放入 .net core 3 应用程序中。据我所知,我不能在 .net 核心中使用 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 核心中运行脚本时在 ps 5.1 中运行脚本?