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

Comparing members of 2 Groups Get-ADGroupMember grouping the output

$
0
0

I am looking to trying to group my output so it completes processing before it gets to first if statement .

My goal is to get my 2 outputs grouped so all users that exist in group are completed processing before going to does not exist in the group.

Here is my Output:

Joe does not exists in the group    Dallas
Lee exists in the group
Cooper does not exists in the group    Dallas

Bob exists in the group
locki exists in the group
GolfUser does not exists in the group   Dallas
Tammy exists in the group
JohnJones does not exists in the group    Dallas
JayJay exists in the group

 

# Destination Users Group
$DestGroup = "Dallas"
$DestMembers = Get-ADGroupMember -Identity $DestGroup | sort |Select -ExpandProperty SamAccountName

# Source Users Group
$SourceGroup = "Detroit"
$SourceMembers = Get-ADGroupMember -Identity $SourceGroup | sort | Select -ExpandProperty SamAccountName


 foreach ($user in $SourceMembers) {
 If ($DestMembers -contains $user) {

      Write-Host "$user exists in the group"
 } Else {
      Write-Host "$user does not exists in the group    $DestGroup" -NoNewline -ForegroundColor Yellow `r`n
         
 }}

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles