【问题标题】:New-PSSession :Connecting to remote server outlook.office365.com failed :The parameter is incorrectNew-PSSession :connecting to remote server outlook.office365.com failed :参数不正确
【发布时间】:2019-05-09 18:27:20
【问题描述】:

我正在尝试在服务器上运行以下命令(在 Windows Server 2012 R2 上运行)以导入交换在线 PowerShell(我正在使用带有 PowerShell 版本 5 的 PowerShell ISE)命令,例如“Search-UnifiedAuditLog " 但每当我运行命令时,我都会收到错误消息。我的代码在我的本地机器(带有 PowerShell V4 的 Windows 7)上工作,但是当我远程连接到服务器以尝试运行命令时它不起作用。

我的目标是让包含此命令的脚本作为计划任务运行,这就是它需要在服务器上运行的原因。我尝试在服务器上的多个用户帐户上运行此命令,但仍然遇到相同的问题。使用与以前相同的用户帐户运行命令,但使用我的本地计算机不会导致错误。

我尝试使用以下命令将执行策略设置为 RemoteSigned,但这没有任何效果。 Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

我当前的代码是这样的;

$ExchangeCredentials = Get-StoredCredential -Target Credentials

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $ExchangeCredentials -Authentication Basic -AllowRedirection

Import-PSSession $Session -DisableNameChecking -AllowClobber

我收到的完整错误是;

New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message : The parameter is incorrect. For more information, see the 
about_Remote_Troubleshooting Help topic.
At line:1 char:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : 87,PSSessionOpenFailed

我希望这个命令能像在我的本地机器上一样运行良好。我找不到其他有同样问题的人。

【问题讨论】:

  • 要检查两件事:1) Get-StoredCredential 不是本机 PowerShell 命令,因此可能是导致问题的原因。 2) 将 URL 更改为仅“/powershell/”
  • $ExchangeCredentials 是否返回 pscredential 对象?执行$ExchangeCredentials.GetType() 并显示结果...
  • 您是否使用 PowerShell 控制台而不是 ISE 对此进行了测试?
  • @I.TDelinquent - 1) 相同的命令在我的本地机器上工作,所以我不认为这是问题所在。 2)我刚刚尝试过,很遗憾我遇到了同样的错误
  • @AdminOfThings - 是的,我在这两个区域都尝试过这些命令,但我得到了同样的错误。

标签: powershell


【解决方案1】:

根据错误消息,New-PSSession 导致了问题。由于所有其他参数看起来都正确,我会检查您传递给Credential 参数的内容。

Get-StoredCredential -Target Credentials 是否获得了正确的PSCredential 对象?

【讨论】:

  • @Avshalom - 我刚刚看了看,对我来说看起来不错,相同的命令在我的本地机器上工作。我已经仔细检查了用户名和密码是否正确,以防万一。 ` IsPublic IsSerial Name BaseType True True PSCredential System.Object `
猜你喜欢
  • 2018-07-08
  • 2018-01-05
  • 2019-07-27
  • 1970-01-01
  • 2019-11-30
  • 2014-03-08
  • 1970-01-01
  • 2016-01-18
  • 2022-12-02
相关资源
最近更新 更多