删除旧的/冗余的activesync伙伴关系

时间:2019-09-26 09:26:05

标签: powershell activesync

我使用脚本来获取所有启用了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连接?

首选文本文件选项以获得更好的目标。

1 个答案:

答案 0 :(得分:0)

我想我自己回答了,所以给别人发帖。

“==============================================================”
“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/