Telephone notes - add all groups user is a member off

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Tim Pringle Tim Pringle 1 year, 12 months ago.

  • Author
    Posts
  • #21101

    Hello everyone 🙂

    I'm a beginner at powershell. My question what script all oneliner would do this: copy all groups that user is a member off, clear member off and paste in to telephones/notes?

    I know command to replace notes Set-ADUser username -Replace @{info='New info for the notes field'} clearing all groups is not a problem as well. But how to copy groups to info?

  • #21103
    Profile photo of Tim Pringle
    Tim Pringle
    Participant

    Unless you've a specific reason for requiring a one-liner, you're talking about involving read and write operations in one go, which I'd normally steer clear of in an Active Directory environment.

    In any case, each AD user account has an attribute called [i]MemberOf[/i], which contains details of each group the user is a member of, and is accessible via the Get-ADUser command.

    Something like the following should work.

    Get-ADUser -Identity JoeBloggs -Properties MemberOf | ForEach-Object -Process {Set-ADUser -Identity $_.DistinguishedName -Replace @{info = $_.memberOf}}

    You will probably be able to drop the

    -Identity $_.DistinguishedName

    part , but the AD cmdlets can sometimes be a bit touchy, so i've put it in for completeness.

    Also note that the .MemberOf property features the DistinguishedName of the group

You must be logged in to reply to this topic.