我正在尝试连接到共享点环境,我想使用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是否有不同的语法或者我做错了什么?此外,也许有一种方法可以在ps 5.1中运行脚本。网芯?
您是否尝试过通过删除凭据部分并让它提示您登录并测试是否成功解决来手动连接?
编辑:我知道你也可以像这样从. bat调用powershell:
powershell -version 2 .\xyz.ps1
但是不知道你到底想要什么,很难建议这是否是一个可行的选择。