#By Alberto Igbinedion
#.SYNOPSIS
#Compare Groups for specified user from two domains AECUK and CDS
#
#.EXAMPLE
#.\CompareuserGroup.ps1 -$users -$CDSGroup - $AECGroup
#Function CompareGroups{ 
[CmdletBinding()]
Param(

    
    [Parameter(
              ValueFromPipeline=$True,
              ValueFromPipeLineByPropertyName=$True)] [string[]]$users
               
                <#[ValidateScript({If ($_ -match 'users,user') {$True 
                } Else { Throw "$_ Please Enter Value User or Users!" } } )]
                $ErrorActionPreference = "Continue"#>    
                
                  
       #[Parameter][string[]]$user1,
       #[Parameter][string[]]$user2,
       #[Parameter][string[]]$CDSGroup,
       #[Parameter][string[]]$AECGroup,
       #[Parameter][string[]]$UserGroup1,
       #[Parameter][string[]]$User1Group2,
       #[Parameter][string]$Export
          
)
Import-Module ActiveDirectory
 
#Export Results 
        #$Export = export-csv c:\scripts\output\Groupdif.csv

#Get User 
        #$user1 =  (Get-ADUser -identity alb100)
        #$user2 =  (Get-ADUser -identity alb100)

#Specify User      
        #Write-host "$User1.$user2._Username" -ForegroundColor Green
          
        #$UserGroup1 = (Get-ADPrincipalGroupMembership -Identity $User1 -server "bhm1dc01.controlsdata.com" )
        #$User1Group2 = (Get-ADPrincipalGroupMembership -Identity $User2 -server "AEC01A-DC03.aecuk.aec.local" )

#Get Contents of Text File
        $users =  gc "C:\Scripts\input\UserListBatch8.txt" 

Foreach($Item in $users) 


{
#Get Groups return by GC

        Write-host "$Item._Username" -ForegroundColor Green

        $AECGroup = (Get-ADPermission  -Identity "CN=Igbinedion\, Alberto,OU=Users,OU=bhx1,OU=Engine Control Systems,DC=aecuk,DC=aec,DC=local" | select user)
        $CDSGroup = (Get-ADPermission  -Identity "controlsdata.com/MigrationSync/Igbinedion, Alberto" | select user)


#Compare Groups and export result
# <= shows Groups in CDS not in AEC
# => Shows Groups In AEC not In CDS
compare-object -ReferenceObject $CDSGroup -DifferenceObject $AECGroup | where {$_.sideindicator -eq "<=" }


}

#}
