在Get-MobileDeviceStatistics

时间:2016-11-28 01:14:11

标签: powershell exchange-server

我正在编写一个脚本来从我们的Exchange服务器中删除所有EAS设备。 (强制使用仅基于REST的客户端)

# 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

我收到以下错误:

  

无法在参数“邮箱”上处理参数转换。无法将值“支持帐户”转换为键入   “Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter”。错误:“无法将哈希表转换为对象   以下类型:Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter。 Hashtable-to-Object转换不是   受限语言模式或数据部分支持。“

我的问题是如何获取所有邮箱,然后遍历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

2 个答案:

答案 0 :(得分:1)

为什么不使用:

Get-MobileDevice -ResultSize unlimited |其中{$ _。clienttype -eq“EAS”} |删除 - 移动设备

这有效地从您的系统中删除了所有EAS类型的合作伙伴关系。

答案 1 :(得分:0)

您需要使用PSSnapin Exchange。我希望这符合你的要求。

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