【问题标题】:Remove old/redundant activesync partnerships删除旧的/冗余的 activesync 伙伴关系
【发布时间】:2020-01-26 13:05:06
【问题描述】:

我使用了一个脚本来获取所有启用了 activesync 的用户并列出所有连接。许多用户有多个条目,他们使用过手机并升级或擦除后重新启用。

我希望删除任何超过 30 天的条目,仅适用于特定 OU 中的用户,或充满用户的文本文件。

我相信此代码将在整个域中通用:

$DevicesToRemove = Get-ActiveSyncDevice -result unlimited | Get-ActiveSyncDeviceStatistics | where {$_.LastSuccessSync -le (Get-Date).AddDays("-30")}

$DevicesToRemove | foreach-object {Remove-ActiveSyncDevice ([string]$_.Guid) -confirm:$false}

但我只想为 OU 或 txt 列表执行此操作。

我可以创建一个包含 UPN 或用户名的 .txt 列表,这可能比在 OU 中查找所有用户更容易。我将如何修改该代码(或完全更好的代码?)以删除该 txt 列表的 30 天+ activesync 连接?

文本文件选项将是更好的目标。

【问题讨论】:

    标签: powershell activesync


    【解决方案1】:

    我想我自己回答了,所以为其他人发帖。

    “==============================================================”
    “Start Mailbox Retrieve”
    “==============================================================”
    $mbx = get-casmailbox -resultsize unlimited | where {$_.activesyncenabled -eq $true} ;
    “==============================================================”
    “End Mailbox Retrieve”
    “==============================================================”
    $mbx | foreach {
    “Processing: “+$_.name
    $name = $_.name;
    $device = get-activesyncdevicestatistics -mailbox $_.identity | where {$_.LastSuccessSync -le (Get-Date).AddDays(“-30”)};
    if($device){
    {
    ”
    Device: “+$dev.DeviceType
    $csvRows += $dev
    }
    }
    }
    “==============================================================”
    “Start CSV Write”
    “==============================================================”
    $csvRows | Export-Csv “c:\ps\staledevices.csv” -NoType
    “==============================================================”
    “End CSV Write”
    “==============================================================”
    

    来自http://techtalklive.org/ttlblog/removing-stale-activesync-devices/

    然后删除:

    Import-Csv c:\ps\staledevices.csv |foreach {remove-activesyncdevice -identity $_.guid -confirm:$false}
    

    来自http://techtalklive.org/ttlblog/removing-stale-activesync-devices/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-26
      • 2011-01-26
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      • 2011-10-22
      相关资源
      最近更新 更多