0

我一直在从事一个涉及 Active Directory 的身份管理项目,并遇到了一个我无法弄清楚 Powershell 的案例。本质上,我们正在查看employeeID 属性,我们希望在整个域中找到该属性中具有相同值的所有用户。用户不应具有相同的employeeID,因此如果有两个或更多具有相同的employeeID。他们需要清理干净。

我知道 Powershell 可以为我做到这一点,但我不确定我需要什么命令。我一直在寻找 Get-ADUser ,但没有什么可以让我开始。我本质上只是想要一个与另一个用户具有相同员工 ID 的所有用户的报告,以便可以清理它们。

4

1 回答 1

2

你可以:

  • 枚举所有具有employeeID值的帐户
  • 根据使用的值对它们进行比较和分组Group-Object
# Fetch all user accounts with an employeeID
$employeeAccounts = Get-ADUser -Filter 'employeeID -like "*"' -Properties employeeID

# Group them by value of employeeID attribute, keep any group with more than 1 account
$accountsByEmployeeID = $employeeAccounts |Group-Object employeeID |Where-Object Count -gt 1

foreach($ID in $accountsByEmployeeID){
  # $accounts will contain a list of accounts with the same employeeID
  # you could send an email, file a ticket, or disable one or more of the accounts here
  $accounts = $ID.Group
}
于 2020-06-11T00:07:34.303 回答