# Clone groups from one user to another 
Function Clone-UserGroups ($PrimaryUser,$CloneUser)
    {
        # Get the user and their group memberships
        $PGroups = Get-ADUser -Identity $PrimaryUser -Properties MemberOf
        $CGroups = Get-ADUser -Identity $CloneUser -Properties MemberOf

        #Initialize PrimaryUser_Groups,ClonedUser_Groups arrays
        $PrimaryUser_Groups = @()
        $CloneUser_Groups = @()
        #$Difference = @()

        # Iterate through each group and add it to the hash table
        foreach ($Group in $PGroups.MemberOf)
            {
                $GroupName = ((Get-ADGroup $Group).DistinguishedName).split(",")
                If ($GroupName.IndexOf("OU=McGuire AFB") -ne -1)
                    {
                        $PrimaryUser_Groups += (Get-ADGroup $Group).Name
                    }
            }
       
        foreach ($Group in $CGroups.MemberOf)
            {
                $GroupName = ((Get-ADGroup $Group).DistinguishedName).split(",")
                If ($GroupName.IndexOf("OU=McGuire AFB") -ne -1)
                    {
                        $CloneUser_Groups += (Get-ADGroup $Group).Name
                    }
            }

        ForEach ($Group in $PrimaryUser_Groups)
            {
                If (($CloneUser_Groups.IndexOf($group) -eq -1))
                    {
                        $Difference += $Group + ","
                    }
            }
       
        $len = $Difference.length - 1
        $Difference = $Difference.substring(0,$len)
        Add-Member2Group -User $CloneUser -Group "$Difference"
        $Name = (get-aduser $CloneUser).Name
        Write-Host "$Name has been added to the following groups:`r`n$Difference"
       

    }