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.
Answers (1)
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()+"$")