I'm trying badly to add multiple existing computer accounts to an AD group and i've tried the following syntax's but none worked:
Import-module ActiveDirectory
foreach ($c in Get-Content c:\pacs_ws.txt) {
add-QADGroupMember -identity 'S-1-5-21-436374069-152049171-725345543-20610' -Member $c
}
The SID is of the Group i want to add the computer account to
Another try: (Which worked with adding a list of users, but not working with a list of computer accounts) – Since both username and computername are AD objects which can be part of ADgroups I thought it should work the same…
Import-module ActiveDirectory
$computers = Get-Content c:\pacs_ws.txt #input list
foreach ($c in $computers) {
add-QADGroupMember -identity 'CN=PacsWorkstationsGrp,OU=Security Groups,OU=Groups,OU=Accounts,DC=asuta,DC=co,DC=il' -Member $c
}
Another try:
foreach ($ws in Get-Content c:\pacs_ws.txt) {
Add-ADPrincipalGroupMembership -identity $ws -MemberOf 'CN=PacsWorkstationsGrp,OU=Security Groups,OU=Groups,OU=Accounts,DC=asuta,DC=co,DC=il'
}
I've tried the updated script but it didn't work: Add-QADGroupMember : Cannot resolve directory object for the given identity: 'asuta.co.il\TAPC03521'. At C:\Users\itaig\AppData\Local\Temp\61810980-c842-4014-a55a-a06a315520a6.ps1:5 char:21 + Add-QADGroupMember <<<< -Identity "S-1-5-21-436374069-152049171-725345543-20610" -Member "$dcPrefix$c" + CategoryInfo : NotSpecified: (:) [Add-QADGroupMember], ObjectNotFoundException + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.DirectoryAccess.ObjectNotFoundException,Quest.ActiveRoles.ArsPowerShellSnapIn.Commands.AddGroupMemberCmdlet2
Now just to make sure the object exists in the directory: DistinguishedName : CN=TAPC03521,OU=HQ,OU=Users Workstations,OU=Workstations,OU=Computers,OU=Accounts,DC=asuta,DC=co,DC=il DNSHostName : TAPC03521.asuta.co.il Enabled : True Name : TAPC03521 ObjectClass : computer ObjectGUID : 39ce0e58-aee7-4a1e-bc29-2178266f8ca4 SamAccountName : TAPC03521$ SID : S-1-5-21-436374069-152049171-725345543-8551