Filter user's from group


We have a security group which has user’s from multiple OU’s, now i’m trying to get it sorted out and move/copy those users to their appropriate group’s. So my questions is, how i can filter out user’s from a group using OU as a filtering parameter?

I know i can get user list using, but that’s pretty much all what i understand from powershell scripting

[pre]Get-ADGroupMember -Identity ‘Groupname’ -Server ‘server.local’[/pre]

You might make a step back and take a little time to start to learn the very basics of Powershell. :wink: … most of the time it is better to learn to walk before you start to run. :smiley: :smiley:

If you like to filter on the OU of a user you can use either the canonical name or the distinguished name of the user. Compaired to the file system would that be a kind of the path of a file.

Yeah i know that, but my work enviroment is kinda hectic and so little time to actually study these things. So my method is to learn on the fly when i’m trying to accomplish something :smiley:

At least for the basics I’d expect this method to take much much longer to become comfortable with a technology like Powershell.

You might try to find something suitable for your requirements in the PowershellGallery.

Most people seem to use -searchbase with another command, then use the output with get-adgroupmember, or vice versa. OU’s can’t be used in filters for some reason.

Took another way around for this.

[pre]Get-ADUser -Server $domain -SearchBase $OU -Properties memberOf -Filter {memberOf -eq $group} | Select-Object Name,MemberOf[/pre]

This gave me the info what i wanted. Now to figure out how to copy those user’s to their appropriate group’s.


You can add accounts to groups with the cmdlet Add-ADGroupMember or Add-PrincipalADGroupMembership. But I’d recommend to use the sAMAccountName instead of the name of the accounts - that’s more specific and less error prone when there are accounts with the same name - lastname combination.
Please read the complete help including the examples to learn how to use these cmdlets.