遍历 Get-MobileDeviceStatistics 上的邮箱
Iterate through mailboxes on Get-MobileDeviceStatistics
我正在编写脚本以从我们的交换服务器中删除所有 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
我收到以下错误:
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 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}
}
为什么不使用:
Get-MobileDevice -ResultSize 无限 |其中 {$_.clienttype -eq "EAS"} |删除移动设备
这有效地从您的系统中删除了所有 EAS 类型的合作伙伴关系。
我正在编写脚本以从我们的交换服务器中删除所有 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
我收到以下错误:
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 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}
}
为什么不使用:
Get-MobileDevice -ResultSize 无限 |其中 {$_.clienttype -eq "EAS"} |删除移动设备
这有效地从您的系统中删除了所有 EAS 类型的合作伙伴关系。