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!
The results of Compare-Object is PSCustomObject(s), it has no members that Add-QADGroupMemberexpect. So, get the ad object by piping to get-qaduser and then add it to group3: