Telephone notes - add all groups user is a member off

Hello everyone :slight_smile:

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?

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 MemberOf, 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