2017-05-09 99 views
0

我目前正在研究一個腳本,該腳本會從組織的終止僱員中刪除會議請求。我發現這一個作爲參考(Deleting Meeting Requests made by terminated users),我不能讓它爲我工作,因爲我的錯誤。術語'搜索郵箱'不被識別爲cmdlet的名稱Exchange Online Powershell

這是我的腳本

Add-Type -Path "C:\Program Files (x86)\Microsoft\Exchange\Web Services\2.1\Microsoft.Exchange.WebServices.dll" 


$UserCredential = Get-Credential 
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection 
Import-PSSession $session -AllowClobber 
#Enter-PSSession $session 

$rooms = Get-Mailbox -RecipientTypeDetails RoomMailbox -ResultSize Unlimited 

$count=$rooms.count 
$TerminatedUsers = Get-Content D:\Work\SHAR78\resignedEmployees.txt 

Write-Host "count of rooms " $count 

foreach ($user in $TerminatedUsers) { 

    Write-Host "terminated user" $user 

    foreach($room in $rooms) { 

     $room | Search-Mailbox -searchquery "kind:calendar from:$($user)" -targetmailbox [email protected] -TargetFolder "SearchData" -logonly -loglevel full 
     #-targetmailbox [email protected] -targetfolder "Deleting Meeting" -deletecontent -force 

    } 
} 

我已連接到Exchange Online,所以我不會知道爲什麼沒有被導入的搜索郵箱。我的帳戶也擁有所有者權限。

+0

您是否檢查了會話中正在導入的內容?也許它沒有公開,這可能是因爲你沒有足夠的權限? – Seth

+0

此cmdlet在本地Exchange Server 2016和基於雲的服務中可用。那麼,您可以使用get-command來查看它是否可用。 –

+0

Hi @Seth我的帳戶需要什麼權限?我檢查使用get-command,我找不到搜索郵箱。我只看到Search-MailboxAuditLog。 –

回答

1

您似乎沒有可用的cmdlet。所以檢查正確的版本。

請執行下列操作,看看:

創建「郵箱導入,導出管理」角色組,併成爲它的成員。

要創建角色組使用:

New-RoleGroup "Mailbox Import-Export Management" -Roles "Mailbox Import Export"

添加的成員:
Add-RoleGroupMember "Mailbox Import-Export Management" -Member

除此之外,如果你想進行搜索,那麼你可以使用這樣的:

Get-mailbox | Export-Mailbox –AllContentKeywords "thekeysyouwant" –TargetMailbox Administrator –TargetFolder 'foldername' 

希望它有幫助。

+0

我現在得到這個:術語'Export-Mailbox'不被識別爲cmdlet,函數,腳本文件或可操作程序的名稱。檢查名稱的拼寫,或者如果包含路徑,請驗證路徑是否正確,然後重試。 –

+0

我相信交換pssnapin有一些問題。你能否請在另一個盒子試試,並檢查 –

+0

嘗試此鏈接。 [LINK](HTTP://www.aurelp。com/tag/resolved-export-mailbox-and-import-mailbox-commands-not-recognized /) –

相關問題