join  Variable A item "User" with Variable B "email"

Hi,

Asking for help on a simple issue.

I have two variables and I would like to combine data from each and then output the results into a CSV.

Can some one please point me in the right direction on how best to do this.

For example,

Variable A, has the following items “User”, “Delegate”, “Status”

Variable B, has the items “group”, “type”, “role”…“email”

I would like to join Variable A item “User” with Variable B “email”

If there is a match I would like to create a new variable which combines these items “User”, “Delegate”, “Status” and “group”, “role”…“email”

I’m just scratching my head on the best way of doing this, and advice is welcome.

Thanks

To combine, you should have some element in common to ensure the right combination. It should be mostly user or email. Do you have anything common between A and B ?

Thanks for getting back, yes the email address is the same in both Variable A and Variable B.

for example - Variable A (User: user.one@test.com) = Variable B (email : user.one@temp.com)

Here is an out put from Variable A :

User Delegate


User: user.one@test.com Show 0 Delegates
User: user.two@test.com Show 1 Delegate
Delegate: user.three@test.com
Status: accepted

User: user.four@test.com Show 2 Delegates
Delegate: user.five@test.com (1/2)
Status: accepted

Delegate: user.six@test.com (2/2)
Status: accepted

User: user.seven@test.com Show 0 Delegates

Here is an out put from Variable B :

group : staff@temp.com
type : USER
role : OWNER
status : ACTIVE
email : user.seven@test.com

group : staff@temp.com
type : USER
role : MANAGER
status : ACTIVE
email : user.three@temp.com

group : staff@temp.com
type : USER
role : MANAGER
status : ACTIVE
email : user.one@temp.com

group : staff@temp.com
type : USER
role : OWNER
status : ACTIVE
email : user.five@temp.com

Note even after changing the temp.com to test.com in Variable B data, only two entries from Variable A match entries from Variable B.

$variableA = @'
User,Delegate,Status
user.one@test.com,,
user.two@test.com,user.three@test.com,accepted
user.four@test.com,user.five@test.com,accepted
user.six@test.com,,accepted
user.seven@test.com,,
'@ | ConvertFrom-Csv

$variableB = @'
group,type,role,status,email
staff@temp.com,USER,OWNER,ACTIVE,user.seven@test.com
staff@temp.com,USER,MANAGER,ACTIVE,user.three@test.com
staff@temp.com,USER,MANAGER,ACTIVE,user.one@test.com
staff@temp.com,USER,OWNER,ACTIVE,user.five@test.com
'@ | ConvertFrom-Csv

$combined = foreach($entry in $variableA)
{
    $variableB | where email -eq $entry.user | ForEach-Object {
        [PSCustomObject]@{
            User     = $entry.user
            Delegate = $entry.Delegate
            Status   = $entry.Status
            Group    = $_.group
            Role     = $_.role
            Email    = $_.email
        }
    }
}

Many thanks for this, I think im on the right track.

Is it possible to contact you directly to get further help on this…? If it’s not possible - not to worry.

Regards