Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » Request a Script

Thread: Need to add users to a new group

This question is not answered. Helpful answers available: 2. Answered answers available: 1.


Permlink Replies: 2 - Pages: 1 - Last Post: Dec 27, 2009 9:29 AM by: Shay Levy
Stef

Posts: 2
Registered: 12/18/09
Need to add users to a new group
Posted: Dec 18, 2009 11:25 AM
 
  Click to reply to this thread Reply

I'm looking to populate a new security group with users that are members of two groups.  So the logic is something like this:

Get users of Group1.
If user from Group1 is a member of Group2
Then add user to Group3.

It seems like this should be fairly simple and could be handled with just a command line but I'm having a hard time with it.

This gives me a list of the people I want:
Compare-Object (Get-QADGroupMember Group1 -sizelimit 0) (Get-ADGroupMember Group2 -sizelimit 0) -property name -IncludeEqual -ExcludeDifferent

But appending
     | addqadgroupmemeber Group3
to the command gives an error of:
Add-QADGroupMember : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.

If it needs to be a script file instead that's fine.  I'm just looking for a way to get this done once.  All help is welcome!



Art Beane

Posts: 49
Registered: 4/23/09
Re: Need to add users to a new group
Posted: Dec 21, 2009 8:18 AM   in response to: Stef
 
  Click to reply to this thread Reply

try .... | foreach { $_ | addqadgroupmemeber Group3 }




Shay Levy


Posts: 1,919
Registered: 1/31/08
Re: Need to add users to a new group
Posted: Dec 27, 2009 9:29 AM   in response to: Stef
 
  Click to reply to this thread Reply

The results of Compare-Object is PSCustomObject(s), it has no members that Add-QADGroupMember expect. So, get the ad object by piping to get-qaduser and then add it to group3:

Compare-Object (Get-QADGroupMember Group1 -Type user) (Get-QADGroupMember Group2 -Type user) -Property name -IncludeEqual -ExcludeDifferent | Get-QADUser -Identity {$_.Name} | Add-QADGroupMember Group3

Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums