Forum Discussion
Need help with a script for adding computers to AD Security Group
- Aug 11, 2022
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
- pedersenchAug 11, 2022Copper ContributorWhen i use $computer i get the same error message as in the first image
- Aug 11, 2022The 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?- pedersenchAug 11, 2022Copper Contributor
I am not sure what you mean, but the group name matches the name it has in AD.
I used the "same" name when removing the users from the old group and that worked without issues.
I was then using this script:
Get-ADGroupMember "Groupname_old" | ForEach-Object {Remove-ADGroupMember "Groupname_old" $_ -Confirm:$false}Edit:
I see now that I gave the wrong script in the original post.
This script is what I originally tried to use:
$List | foreach{Add-ADGroupMember -id "groupname" -MEMBERS(Get-ADComputer $_)}
I am not sure of the connection between the removal of computers from the old group and adding computers to the new group, but there seems to be some type of connection with the "$_" at the end.