【问题标题】:Iterate through mailboxes on Get-MobileDeviceStatistics遍历 Get-MobileDeviceStatistics 上的邮箱
【发布时间】:2016-11-28 22:04:25
【问题描述】:

我正在编写一个脚本以从我们的交换服务器中删除所有 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。哈希表到对象的转换不是 受限制的语言模式或数据部分支持。"

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

【问题讨论】:

    标签: powershell exchange-server


    【解决方案1】:

    为什么不使用:

    Get-MobileDevice -ResultSize 无限制 |其中 {$_.clienttype -eq "EAS"} |删除-MobileDevice

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

    【讨论】:

      【解决方案2】:

      您需要为此使用 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}
      }
      

      【讨论】:

        猜你喜欢
        • 2014-07-01
        • 2019-02-28
        • 1970-01-01
        • 2021-10-24
        • 2011-02-28
        • 1970-01-01
        • 2015-06-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多