Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
1  
Can you show what your text file looks like? –  Christopher Feb 7 '12 at 15:42
    
Thanks for your reply. My text file looks like this and contains about 400 computer names: TAPC03085 TAPC04498 TAPC04801 TAPC01157 TAPC02957 Itai –  Itai Ganot Feb 7 '12 at 18:16
    
each computer account in a different line –  Itai Ganot Feb 7 '12 at 18:16
    
Are you getting any error message at all? –  Christopher Feb 7 '12 at 19:36
    
Yes this is the error i get: Add-QADGroupMember : Ambiguous identity: TAPC03090. At line:1 char:62 + foreach ($c in Get-Content c:\pacs_ws.txt){add-QADGroupMember <<<< -identity 'CN=PacsWorkstationsGrp,OU=Security Groups,OU=Groups,OU=Accounts,DC=asuta,DC=co,DC=il' -Member $c} + CategoryInfo : NotSpecified: (:) [Add-QADGroupMember], IdentityException + FullyQualifiedErrorId : Quest.ActiveRoles.ArsPowerShellSnapIn.BusinessLogic.IdentityException,Quest.Acti‌​veRoles.ArsPowerShellSnapIn.Commands.AddGroupMemberCmdlet2 –  Itai Ganot Feb 8 '12 at 8:01

2 Answers 2

If you are already using the Quest AD cmdlets, have you tried using Get-QADComputer to get the computer account and then pass that on as the Member property?

Import-module ActiveDirectory
$dcPrefix = "asuta.co.il\"
$computernames = Get-Content c:\pacs_ws.txt #input list
foreach ($c in $computernames) {
  Add-QADGroupMember -Identity "S-1-5-21-436374069-152049171-725345543-20610" -Member "$dcPrefix$c"
}

Alternatively, just prepend the Computer account name with the domain FQDN, instead of just the computer account name

share|improve this answer
    
Hey, from reading the script you wrote i was sure it's going to work but it didn't, the error i get is: Add-QADGroupMember : Cannot validate argument on parameter 'Member'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again. At C:\Users\itaig\AppData\Local\Temp\7d091a6f-0e7f-49a8-9c72-ef7b6d516f34.ps1:7 char:59 + Add-QADGroupMember -Identity "$dcPrefix$groupCN" -Member <<<< $computerAccount + CategoryInfo : InvalidData: (:) [Add-QADGroupMember], ParameterBindingValidationException –  Itai Ganot Feb 8 '12 at 8:03
    
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Quest.ActiveRoles.ArsPowerShellSnapIn.Commands.‌​AddGroupMemberCmdlet2 –  Itai Ganot Feb 8 '12 at 8:04
    
What if you remove the $computeraccount variable, and just use "$dcPrefix$c" as the member property? –  Mathias R. Jessen Feb 8 '12 at 9:30
    
I've tried it already... it gives me the following error: Add-QADGroupMember : Cannot resolve directory object for the given identity: 'asuta.co.il\PacsWorkstationsGrp'. It seems like the identity value is incorrect or something –  Itai Ganot Feb 8 '12 at 10:11
    
Try with an alternative identity reference. Just updated the answer –  Mathias R. Jessen Feb 8 '12 at 10:19
up vote 0 down vote accepted

This solved my issue:

Import-Module ActiveDirectory
Get-Content c:\pacs_ws.txt | foreach-object  { get-qadcomputer $_ | add-qadgroupmember -Identity PacsWorkstationsGrp }

Thanks to everyone who tried to help me. Itai

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.