1

我正在尝试连接到共享点环境,并且我想使用 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 中运行脚本?

4

1 回答 1

1

您是否尝试过通过删除凭据部分并让它提示您登录并测试是否成功解决来手动连接?

编辑:我知道你也可以像这样从 .bat 调用 powershell:

powershell -version 2 .\xyz.ps1

但不知道你到底要做什么,很难建议这是否是一个可行的选择。

于 2019-12-17T17:09:35.147 回答