【问题标题】:Unable to Disconnect a powershell session connected to office365无法断开连接到 office365 的 powershell 会话
【发布时间】:2019-10-25 17:17:55
【问题描述】:

我想断开连接到 office365 的远程 powershell 并稍后再连接。

尝试了Disconnect-PSSession 命令,但它会引发错误。

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

.
.
.
.

Disconnect-PSSession $Session

(它重定向到https://nam04b.ps.compliance.protection.outlook.com/powershell-liveid?PSVersion=4.0

我看到的输出是:

disconnect-pssession : Disconnect-PSSession operation failed for runspace Id = 613e8071-b691-4365-84dc-2d65c21ea2fa
for the following reason: The disconnection operation is not supported on the remote computer. To support
disconnecting, the remote computer must be running Windows PowerShell 3.0 or a later version of Windows PowerShell.
At line:1 char:15
+ get-pssession|disconnect-pssession
+               ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ([PSSession]Session1:PSSession) [Disconnect-PSSession], RuntimeExcepti
   on
    + FullyQualifiedErrorId : PSSessionDisconnectFailed,Microsoft.PowerShell.Commands.DisconnectPSSessionCommand

在本地,我正在运行 Powershell 版本 4。 Get-PSSessionConfiguration 在服务器上显示 PSVersion 4。任何帮助表示赞赏

【问题讨论】:

  • $Session | Remove-PSSession 工作吗?

标签: powershell powershell-3.0 powershell-4.0


【解决方案1】:

正如 Theo 指出的那样,使用 Remove-PSSession 可以工作,因为它在低于 3 的 PowerShell 版本中受支持,而 Disconnect-PSSession 仅在PowerShell v3。因此你的错误信息。

请查看此链接到Disconnect-PSSession 的统计信息:

此 cmdlet 是在 Windows PowerShell 3.0 中引入的。

【讨论】:

  • 我正在运行 Powershell 版本 4。而这里的远程计算机是 Office 365 的 powershell 会话。我们如何检查它的版本? Invoke-Command -Session $Session -Scriptblock {$PSVersionTable.psversion} 抛出错误。
  • The syntax is not supported by this runspace. This can occur if the runspace is in no-language mode. + CategoryInfo : ParserError: ($PSVersionTable.psversion:String) [], ParseException + FullyQualifiedErrorId : ScriptsNotAllowed + PSComputerName : nam04b.ps.compliance.protection.outlook.com
  • 取自:michev.info/Blog/Post/1687/… 很多人可能都知道,连接到 Exchange Online 的远程 PowerShell 会话以“无语言”模式运行。这同样适用于 Skype for Business Online 会话,而且通常是皇室背后的痛苦,因为它会阻止您使用变量、运算符和其他可以让您的生活更轻松的东西。
猜你喜欢
  • 1970-01-01
  • 2021-01-24
  • 1970-01-01
  • 1970-01-01
  • 2018-10-26
  • 2018-10-24
  • 1970-01-01
  • 1970-01-01
  • 2021-09-25
相关资源
最近更新 更多