I had question open for this same issue ( https://www.experts-exchange.com/questions/28976646/Error-Importing-Computer-Accounts-From-a-Text-File-using-Add-ADGroupMember.html
) before which Yo_Bee helped with with and did get it working. Thanks Yo_Bee!!!
When I tried to run the script again this morning. I am getting the following error..
Get-ADComputer : Cannot convert 'System.Object' to the type 'Microsoft.ActiveDirectory
required by parameter 'Identity'. Specified method is not supported.
+ $DN = (Get-ADComputer -Identity $devices).distinguishednam
+ CategoryInfo : InvalidArgument: (:) [Get-ADComputer], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Micr
In my text file as soon as I narrow down my list to one device it works. It is almost like the foreach loop in not working
$devices = Get-Content 'C:\workstations.txt'
$grp = (Get-ADGroup -Identity '8021xEnabledDevices').distinguishedname
Foreach ($dn in $devices)
$DN = (Get-ADComputer -Identity $devices).distinguishedname
Add-ADGroupMember -Identity $grp -Members $dn}