【发布时间】:2021-05-10 05:15:18
【问题描述】:
我需要在运行空间中执行 Get-MailboxStatistics。 我可以在线连接到 Exchange。如果我执行“Get-Pssession”,我可以看到 Exchange 会话。但是如何将此 ExchangeOnline 会话传递给运行空间以执行 Get-MailboxStatistics。 目前它无法识别运行空间中的 Get-MailboxStatistics 命令。
这是我的代码(这是较大脚本的一部分):
# Connecting to Exchange Online
$AdminName = "hil119"
$Pass = "password"
$cred_cloud = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Pass
Connect-ExchangeOnline -Credential $cred_cloud -Prefix Cloud
# Executing Get-MailboxStatistics in a Runspace
$Runspace = [runspacefactory]::CreateRunspace()
$PowerShell = [powershell]::Create()
$PowerShell.runspace = $Runspace
$Runspace.Open()
[void]$PowerShell.AddScript({Get-MailboxStatistics 'd94589'})
$PowerShell.BeginInvoke()
【问题讨论】:
-
您说的是线程,但是您使用的是完全不同的运行空间。如果您要坚持使用此代码,则需要同步运行空间。
-
好的,我在问题中用运行空间替换了线程。虽然最初的问题仍然存在。如何让会话进入运行空间
标签: multithreading powershell exchange-server runspace poshrsjob