Adding Add-ADGroupMember to ADObject

Hello I am trying to add group member to an account in AD that’s and object does not have an Identity. Therefore, I can run the following command
Add-ADGroupMember -Identity “ISD OPS NOB…” -Members SQL34

Example I the do a Get-ADObject I get the following

Description : - On Leave 07/06/2023
DistinguishedName : CN=Brasw, Rubin R.,OU=SSA Contact,OU=CDAA Contact,DC=CDAA,DC=DAA,DC=CA,DC=GOVE
memberOf : {CN=ISD OPS NOB SVR AD On Leave Users,CN=Users,DC=CDSS,DC=DSS,DC=CA,DC=GOV}
Name : Brasw, Rubin R.
ObjectClass : contact
ObjectGUID : 0f6b832c-d5b9-4612-9023-
PropertyNames : {Description, DistinguishedName, memberOf, Name…}
AddedProperties : {}
RemovedProperties : {}
ModifiedProperties : {}
PropertyCount : 6

How to I add an Add-ADGroupMember to ADObject?

Frank,
Welcome to the forum. :wave:t3:

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )

That’s impossible. You can only add members to an “AD Group”.

Are you sure you did not wnat to add the contact in your sample output to a group … so the other way around?

Thanks for the response, I am new to this group and still learning., I did not get a notificatioin when you responded sorry for the late response. Maybe that is what I need to do “Are you sure you did not wnat to add the contact in your sample output to a group” However, I could not find the method or command line to do it. how to I do it; I am using the wrong command " Add-ADGroupMember" ? Also, I can add it via the AD console window however, not on the command line.

Yes, you are correct that’s how the command work per what I read however, this is my actual command

Get-ADObject -Filter {(Name -like "*wilson*ronette*") -and (ObjectClass -eq "contact")} | Format-List

and the result is

DistinguishedName : CN=Wilson, Ronette,OU=SS Contact,OU=CD Contact,DC=CD,DC=D,DC=CB,DC=VOG
Name : Wilson, Ronette
ObjectClass : contact
ObjectGUID : 34675e704d0f-0e0b2535-7c00-4deb-bcf0

Therefore, as you can see they are no user ID or SAM account name properties; the acounts are of type Contact only.

The parameter -Identity is “ISD OPS NOB… ” the issues is the -’ ’ -Members ’ since this command as work fine with a user or SAM account name

I’ve learned something today … it seems like you cannot use Add-ADGroupMember to add new members of the type contact to AD groups.

But as almost always there is a solution … you can use the cmdlet Set-ADGroup with the parameter -Add instead.

$NewMember = 
    Get-ADObject -Filter {(Name -like "*wilson*ronette*") -and (ObjectClass -eq "contact")} 
Set-ADGroup -Identity 'ISD OPS NOB…' -Add @{'member' = $NewMember.DistinguishedName}
1 Like

Good Morning, I will try it and see if it works.

Thnaks it work I know i will figure out how to do it reading from a list of file which has work for me before. One question how to learn more are about this method or process in powershell @{'member' = $NewMember.DistinguishedName I have only been doing powershell this years.

I don’t know how to actually put that … :thinking: … reading reading reading!? … :man_shrugging:t3:

As noted in the answer on the linked StackOverflow question … every Set-<ADObject> cmdlet supports the parameters -Add, -Remove, -Replace and -Clear. So you bring up the help for any of the possible cmdlets navigate to the parameter -Add and start reading … :man_shrugging:t3:

Please always read the complete help including the examples to learn how to use them.

Oh, I was just inquiring on the use of @ [@ hash tables (aka custom columns)] after -Add. Nevertheless, I will do some research.

custom columns”?? :thinking: :thinking:

If you want to learn more about using hashatbles in PowerShell you should read about hashtables in the PowerShell documentation …

:man_shrugging:t3:

2 Likes