简体   繁体   English

使用PowerShell如何像使用Get-ADUser一样搜索和筛选一系列导出的Active Directory用户?

[英]Using PowerShell how can I search and filter an array of exported Active Directory users like I can with Get-ADUser?

I have a PowerShell script that compares the contents of a CSV file with Active Directory. 我有一个PowerShell脚本,用于将CSV文件的内容与Active Directory进行比较。 The CSV file contains a list of demographic information of people already in AD. CSV文件包含AD中已有人员的人口统计信息列表。 One of the columns is "emplid". 列之一是“ emplid”。 The values in this field correspond to the values of the "employeeID" attribute of user objects in AD. 此字段中的值对应于AD中用户对象的“ employeeID”属性的值。 So, I currently use this "emplid" property to cross reference AD and find the corresponding user accounts. 因此,我目前使用此“ emplid”属性来交叉引用AD并找到相应的用户帐户。 To do this I use a line similar to this: 为此,我使用类似于以下内容的行:

$UserAccounts = $ListOfEmloyeeIDs | ForEach-Object {Get-ADUser -Properties * -Filter {employeeID -Eq $_}}

I then use this to add those user accounts to a security group: 然后,我将其用于将这些用户帐户添加到安全组中:

$UserAccounts.SamAccountName | ForEach-Object {Add-ADGroupMember -Identity SpecialSecurityGroup -Members $_}

The problem is with the first line. 问题出在第一行。 There are thousands of user accounts and the script can take hours to run. 有数千个用户帐户,脚本可能需要几个小时才能运行。 This has also led to complaints from the AD admins. 这也导致了广告管理员的投诉。 What I would like to do is load all active AD users into a variable (which takes less than 2 minutes to run) using: 我要执行的操作是使用以下命令将所有活动AD用户加载到变量中(运行时间不到2分钟):

$ADPeopleActive = Get-ADUser -SearchBase "OU=People,DC=MyAD,DC=com" -Properties EmployeeID -Filter {Enabled -Eq $True}

Then I would like to do my cross reference against this array and build a list of SamAccountNames to feed to something like my second line to populate my security group. 然后,我想对此数组进行交叉引用,并构建一个SamAccountNames列表,以馈入类似于第二行的内容,以填充我的安全组。

My problem is I can't figure out a way to do this cross reference against an array that I've built the same way I can cross reference with AD using Get-ADuser. 我的问题是我想不出一种方法,可以对使用我使用Get-ADuser与AD进行交叉引用的方式构建的数组进行交叉引用。 Can anyone help? 有人可以帮忙吗?

Something like 就像是

$UserAccounts = $ADPeopleActive| Where-Object { $ListOfEmloyeeIDs -contains $_.EmployeeID }

?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PowerShell Active Directory - 无法在 Get-ADUser 过滤器中使用数组值 - PowerShell Active Directory - Can't use array value in filter for Get-ADUser 如何在Powershell中从Get-ADuser cmdlet输出中排除多个用户? - How can I exclude multiple users from Get-ADuser cmdlet output in powershell? 如何从 Powershell 脚本中的 Get-ADUser 过滤器获取结果,以便验证该用户是否存在? - How can I get results from Get-ADUser Filter in my Powershell script so I can validate if that user exists or not correctly? 我可以在变量中传递Powershell Get-ADUser -Properties吗? - Can I pass Powershell Get-ADUser -Properties in a variable? 我不能在 Get-ADUser 中使用变量吗 - Can I not use a variable in with Get-ADUser Powershell-Get-AdUser:排除数组中的用户 - Powershell - Get-AdUser: Exclude users in array 在 Powershell 中,如何从 Get-ADUser 结果中删除前 x 个字符? - In Powershell how can I remove the first x number of characters from Get-ADUser results? 使用 Get-AdUser 时如何根据 Powershell 中的多个条件过滤用户 - How to filter users based on several criteria in Powershell when using Get-AdUser 如何使Powershell以逗号分隔输出Get-ADUser -Filter *? - How do I get Powershell to output Get-ADUser -Filter * as comma delimited? Powershell Active Directory-将我的获取用户搜索限制为特定的OU [和子OU] - Powershell Active Directory - Limiting my get-aduser search to a specific OU [and sub OUs]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM