I am having a hard time finding a way to add a computer to an AD group with ADSI while specifying credentials. I am able to add the computer to the group WITHOUT specifying credentials via the following method, but I need to be able to specify credentials for what I’m doing.
$group = [adsi]"LDAP://$DC/$GroupDN" $group.add("$DC/$ComputerDN")
I have tried playing around with System.DirectoryServices.DirectoryEntry and am able to make the connection with credentials, but not sure how to grab the group name from there and add the computer. Any suggestions are appreciated.
$objDomain = New-Object System.DirectoryServices.DirectoryEntry('LDAP://$domain/$OU',$username,$password)