Forum Discussion

jcasqueiro's avatar
jcasqueiro
Brass Contributor
May 06, 2024
Solved

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...
  • VasilMichev's avatar
    May 06, 2024
    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.

Resources