Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

add computers to an ad group based on the members of another ad group

$
0
0

i hope the title of this post isnt very confusing...

 

at work, all our computers have names based on the users username, and what i need to do is to update an AD group with the computernames belonging to a list of users.

 

so, i started out with 

get-adgroupmember -identity "superusers" | select object -property SamAccountName | | foreach {$_.samaccountname}

 

this nets me a sweet list of all the user IDs like "ABCD" and "EFGH"

Then i though i could ask the AD for the corresponding computername, like this:

 

Get-ADComputer -Filter 'name -like "ABCD-*"' | Select-Object -Property name

and that works like a charm!

 

getting this to work together is what i need some help with though, i thought i could mash it up like this:

 

$superusers = Get-ADGroupMember -Identity "superusers" | Select-Object -Property SamAccountName | foreach {$_.samaccountname}

foreach ($user in $superusers)

{

    Get-ADComputer -filter 'Name -like "$user"'   

}

 

but it doenst work =/

 

i do get the results i want in the $superusers variable but from there on.... im stuck!

 

any ideas?

 


Viewing all articles
Browse latest Browse all 8583

Trending Articles