bndit
asked on
Optimize Powershell (Quest AD) script to populate AD group
Hello,
I have a script that I'd like to use to maintain distribution groups in Active Directory current. I search for a keyword in the title AD attribute and then I add the member to the group. My script works, but it seems that it's taking a little while to complete. I've used the [void] types in an attempt to speed up the script but still slow especially when adding 1000+ users to the group. Another area where my script might be slow is in the fact that I "rebuild" the group every time....in other words, I clear it first and then add the members all over again.
I'm looking to see if someone out there can provide me with tips on how to speed up this script. Thanks.
I have a script that I'd like to use to maintain distribution groups in Active Directory current. I search for a keyword in the title AD attribute and then I add the member to the group. My script works, but it seems that it's taking a little while to complete. I've used the [void] types in an attempt to speed up the script but still slow especially when adding 1000+ users to the group. Another area where my script might be slow is in the fact that I "rebuild" the group every time....in other words, I clear it first and then add the members all over again.
I'm looking to see if someone out there can provide me with tips on how to speed up this script. Thanks.
# Params
$filter = "(title=*keyword*)"
$scope = 'dc=domain,dc=local'
$Group = Get-QADGroup -Identity "My-Group"
# Clear group
[void](Set-QADGroup -Identity $Group.DN -Member $NULL)
# Get all enabled Active Directory accounts
$Searcher = Get-QADUser -Enabled -SearchRoot $scope -IncludedProperties title -LdapFilter $filter -SizeLimit 0
# Add each account to the specified group
$Searcher | ForEach-Object {
[void](Add-QADGroupMember -Identity $Group.DN -Member $_.DN )
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you.
ASKER
Thanks again.