【发布时间】: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