2016-11-28 39 views
1

我正在使用腳本從我們的交換服務器中刪除所有EAS設備。 (強制使用基於REST的唯一客戶端)Get-MobileDeviceStatistics上的郵箱迭代

# Login 
$UserCredential = Get-Credential 
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic - 

AllowRedirection 
Import-PSSession $Session 

#Removing EAS devices 
# 
$Mailboxes = Get-Mailbox -ResultSize Unlimited 
Foreach ($box in $Mailboxes){ $EASDevices = Get-MobileDeviceStatistics -Mailbox $box | Where-Object {$_.ClientType -like "EAS"}; 
EASDevices | foreach {$Guid = $_.guid.ToString(); Remove-MobileDevice -id $Guid}} 

#@TODO add -Confirm:$False when it is working 

我得到以下錯誤:

Cannot process argument transformation on parameter 'Mailbox'. Cannot convert value "Support Account" to type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter". Error: "Cannot convert hashtable to an object of the following type: Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter. Hashtable-to-Object conversion is not supported in restricted language mode or a Data section."

我的問題是如何讓所有郵箱,然後通過迭代Get-MobildeDeviceStatistics

我沒能更進一步,甚至在網上搜索,例如:

https://social.technet.microsoft.com/Forums/exchange/en-US/1fea011d-484d-4b0a-badf-6f5fcc3ae097/powershell-mobile-devices-full-list-information?forum=exchange2010

https://social.msdn.microsoft.com/Forums/office/en-US/1765335e-fd1c-4886-9fac-b2f15d5a493a/hashtabletoobject-conversion-is-not-supported?forum=exchangesvrdevelopment

回答

1

爲什麼不使用:

獲取,移動設備-ResultSize無限|其中{$ _。clienttype -eq「EAS」} | Remove-MobileDevice

這可以有效地從您的系統中刪除所有EAS類型的合作關係。

0

您需要使用PSSnapin交易所這一點。我希望這能滿足你的要求。

Add-PSSnapin exchange -erroraction SilentlyContinue; 
$Mailboxes = Get-Mailbox -ResultSize Unlimited; 
foreach ($box in $Mailboxes) 
{ 
$EASDevices = Get-MobileDeviceStatistics -Mailbox $box | Where-Object {$_.ClientType -like "EAS"}; 
$EASDevices | %{$Guid = $_.guid.ToString(); Remove-MobileDevice -id $Guid} 
}