/build/static/layout/Breadcrumb_cap_w.png

Adding computers to a group memebership

HI all,


I am having issues with PowerShell to add a group membership called All_desktops to a computer in a domain.

Import-Module ActiveDirectory

$objOU=[ADSI]“LDAP:// OU=IITS,OU=Desktops,OU=Users and Computers,DC=subdomain,DC=Domain,DC=ca

$All_Desktops = "All_Desktops"

ADD-ADGroupMember -identity "All_Desktops” "$env:computername"


this is the error ADD-ADGroupMember : Cannot find an object with identity: 'my computer name' under:


any help would be great.


Thanks.



0 Comments   [ + ] Show comments

Answers (1)

Posted by: Nico-123 2 months ago
White Belt
0

To add a computer to a AD-Group you have to use the sAMAccountName of the computer. Normally it's the hostname and a $ afterwards. For example you computer is named PC-1 your sAMAccountname is PC-1$.

With Powershell you can easily manipulate the input string as shown below:

Add-ADGroupMember -Identity test-group -Members ($env:COMPUTERNAME.ToString()+"$")

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ