Darrin Crawford
asked on
AD Tool/Script Populate Security Groups Automatically
Looking for a simplistic tool/script to auto populate Security Group(s) in AD.
So the tool/script scans each User and if a particular Security Group(s) isn't in their Member of List, it gets populated.
Obviously need this run automatically every few days
So the tool/script scans each User and if a particular Security Group(s) isn't in their Member of List, it gets populated.
Obviously need this run automatically every few days
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
getting multiple errors from line 16
ForEach ($Child In $arrChildren)
# Only consider user objects.
If ($Child.Class -eq "user")
# Add all users in the OU to the hash table.
$List.Add($Child.distingui shedName, $True)
# Check if user a member of the group.
If ($Group.IsMember($Child.AD sPath) -eq $False)
{
# Add the user to the group.
$Group.Add($Child.ADsPath)
"Added " + $Child.distinguishedName
PS C:\Windows\system32> C:\Users\darrin.crawford\D ocuments\P owershell_ AD_Conflue nce Check.ps1
At C:\Users\darrin.crawford\D ocuments\P owershell_ AD_Conflue nce Check.ps1:16 char:33
+ ForEach ($Child In $arrChildren)
+ ~
Missing statement body in foreach loop.
At C:\Users\darrin.crawford\D ocuments\P owershell_ AD_Conflue nce Check.ps1:18 char:30
+ If ($Child.Class -eq "user")
+ ~
Missing statement block after If ( condition ).
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordE xception
+ FullyQualifiedErrorId : MissingForeachStatement
ForEach ($Child In $arrChildren)
# Only consider user objects.
If ($Child.Class -eq "user")
# Add all users in the OU to the hash table.
$List.Add($Child.distingui
# Check if user a member of the group.
If ($Group.IsMember($Child.AD
{
# Add the user to the group.
$Group.Add($Child.ADsPath)
"Added " + $Child.distinguishedName
PS C:\Windows\system32> C:\Users\darrin.crawford\D
At C:\Users\darrin.crawford\D
+ ForEach ($Child In $arrChildren)
+ ~
Missing statement body in foreach loop.
At C:\Users\darrin.crawford\D
+ If ($Child.Class -eq "user")
+ ~
Missing statement block after If ( condition ).
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordE
+ FullyQualifiedErrorId : MissingForeachStatement
You've stripped out "{" characters all over the place. They're not there as decoration.
ASKER
Apologies, I didn't see the full script.
It is now working but has removed all users from this particular Security Group!!
It is now working but has removed all users from this particular Security Group!!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, got it, I needed to dig down into my OUs.
Thanks for your help
Thanks for your help
ASKER
Thanks for the prompt reponses
Open in new window
The search might be a bit more constrained than that of course.