Link to home
Start Free TrialLog in
Avatar of MilesLogan
MilesLoganFlag for United States of America

asked on

Powershell - Check two AD groups and show difference

Hi EE

Can someone help me with a script ? I need to check groupA and groupB and show the difference in users from both.

So if groupA has 50 users , groupB has 40 , for it to export " 10 " or "10 missing accounts"
Avatar of SubSun
SubSun
Flag of India image

Try..
Function Check-GroupDiff ($GroupA,$GroupB){
Compare (Get-AdGroupMember $GroupA -Recursive | 
Select -ExpandProperty SamAccountName) (Get-AdGroupMember $GroupB -Recursive | 
		Select -ExpandProperty SamAccountName) | %{
	If ($_.SideIndicator -eq "=>"){
	 $_ | Select @{N="User";E={$_.InputObject}},@{N="MissingIN";E={$GroupA}}
	 }Else{
	 $_ | Select @{N="User";E={$_.InputObject}},@{N="MissingIN";E={$GroupB}}
	 }
 }
}
Check-GroupDiff HelpdeskAdminGroup DesktopAdminGroup

Open in new window

Avatar of MilesLogan

ASKER

hi Subsun , thats an awesome function but... what I was hoping to do is just get the total number of users.

If GroupA has 10 users and groupB has 4 users , I need it to show the difference .

so basically for it to output , "6 users missing from groupB "

can you help with this ?
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

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
Very cool ! thank you Subsun
..
thank you so much!