So I'm not very knowledgeable with PowerShell, and am hoping to get a little help with writing a script. Any help is greatly appreciated.
The logic of the script is as follows:
Loop through all the users in a certain OU in Active Directory
Find their 'department' (which is a five-digit number)
Add "grp" before the department and assign that to a string
Add the user to the security group of that name (i.e. grp10500)
If the security group doesn't exist, skip onto the next one.
Below is what I've got so far, with comments thrown in for what I haven't been able to write yet.
Import-Module ActiveDirectory
$users=$i=$null
$strCC
$strGRP='grp'& strCC
$users=Get-ADUser-SearchBase"ou=Test,ou=OurUsers,ou=Logins,dc=domain,dc=com"-filter*-department
ForEach($userin$users)
{
# get their department from AD and assign it to strCC
# strGRP will add the letters "grp" before it
{
Add-ADGroupMember'strGRP'-Members$_.DistinguishedName
# if group doesn't exist, skip and move on
$i++
}
}
$users=$i=$null
$strCC
$strGRP='grp'& strCC
$users=Get-ADUser-SearchBase"ou=Test,ou=OurUsers,ou=Logins,dc=domain,dc=com"-filter*-department
ForEach($userin$users)
{
# get their department from AD and assign it to strCC
# strGRP will add the letters "grp" before it
{
Add-ADGroupMember'strGRP'-Members$_.DistinguishedName
# if group doesn't exist, skip and move on
$i++
}
}