Forum Discussion
Need help with a script for adding computers to AD Security Group
I have exported all computer names to a .csv file and am trying to add these to a security group
This is the script i am trying to run:
$Computers = Get-Content c:\Temp\clients.csv
foreach ($computer in $computers) {
Add-ADGroupMember -ID "groupname" -Members $computer
}
This is the error i am getting for every computer:
this is a script thats been used earlier to move computers to a new group after removing them from an older group, to update a program used, but it is not working now.
Edit:
Tried running the script like this:
$Computers = Get-Content c:\Temp\clients.csv
foreach ($computer in $computers) {
Add-ADGroupMember -ID "groupname" -Members (Get-ADComputer $computers)
}
Now i get this:
The problem's with the CSV.
If you look at the first error shown - which is reflective of the contents of the CSV, the computer "name" within the error does not include the obligatory dollar sign as the final character, meaning it's not the actual sAMAccountName but simply the common name.
So, where the name from the error "W100135TRO87" does not work, "W100135TRO87$" would work.
Cheers,
Lain
7 Replies
- I think it's Add-ADGroupMember -ID "groupname" -Members (Get-ADComputer $computer) , you are using $computers instead of $computer in your foreach loop
- pedersenchCopper ContributorWhen i use $computer i get the same error message as in the first image
- The parameter ID (Identiy( shhould match these:
Specifies an Active Directory group object by providing one of the following values. The identifier in parentheses is the Lightweight Directory Access Protocol (LDAP) display name for the attribute. The acceptable values for this parameter are:
A distinguished name
A GUID (objectGUID)
A security identifier (objectSid)
A Security Account Manager account name (sAMAccountName)
Is the group name the SamAccountName or the display name perhaps?