2016-11-28 1 views
1

私はExchangeサーバーからすべての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を反復処理する方法ですか?

私ものようなオンライン検索を更に多く得ることができませんでした:あなたはこのためにPSSnapinコマンド所を使用する必要が

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

。私はこれがあなたの要求を満たすことを願っています。

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} 
}