Link to home
Start Free TrialLog in
Avatar of Alex
AlexFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Object issues with Powershell

Ok so,

I've got this code, it pulls the CSV file which is a file named the same as the group, the file contains the objects within the group. in this case, computer objects.

$groups = get-content "C:\JLBR\JLBR.txt"
Foreach ($group in $Groups) {Import-csv "C:\JLBR\$($group).csv" | ForEach-Object {Add-ADGroupMember -Identity $Group -Members $_.name}}

Open in new window


Now, this code kinda works, well, it doesn't I get the error

Add-ADGroupMember : Cannot find an object with identity: 'CS-Computername' under: 'DC=net,DC=Domainaccept,DC=co,DC=uk'.
At line:2 char:83
+ ... ForEach-Object {Add-ADGroupMember -Identity $Group -Members $_.name}}
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ('CS-Computername:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
    + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember


I think this is because I'm trying to add a computer object, any ideas?

Thanks
Alex
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Alex

ASKER

My hero! You have to give me a little credit though, with your help I've gotten better ;-)

Thanks mate :D