Forum Discussion
jcasqueiro
May 06, 2024Brass Contributor
PS Script | Inserting users in groups based on user fields content
Hi,
I am trying to enroll users in specific groups based on their department and office fields content. I can go to each group (via Entra) and define dynamic rules but it will take ages as I have hundreds of groups.
Is there a way, through scripting, to insert users in specific groups based on the content of user fields?
Example: userA with department=dpto1 and office=ofc1 would be automatically enrolled in group
dpto1-ofc1@domain
Thanks/Brgds
joao
- Sure, should be doable via PowerShell, try something like this:
foreach ($user in $users) {
Add-DistributionGroupMember ($user.department + $user.office) -Member $user.UserPrincipalName
}
where I'm assuming you're passing a user object (Get-User), so the aforementioned properties are readily available.
- Sure, should be doable via PowerShell, try something like this:
foreach ($user in $users) {
Add-DistributionGroupMember ($user.department + $user.office) -Member $user.UserPrincipalName
}
where I'm assuming you're passing a user object (Get-User), so the aforementioned properties are readily available.