我需要在运行空间中执行 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()