Welcome › Forums › General PowerShell Q&A › join Variable A item “User” with Variable B “email”
- This topic has 4 replies, 3 voices, and was last updated 5 days, 18 hours ago by
Participant.
-
AuthorPosts
-
-
January 12, 2021 at 4:04 pm #285538
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
-
January 13, 2021 at 8:23 am #285619
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 ?
-
January 13, 2021 at 1:16 pm #285661
Thanks for getting back, yes the email address is the same in both Variable A and Variable B.
for example – Variable A (User: [email protected]) = Variable B (email : [email protected])
Here is an out put from Variable A :
User Delegate
— ———
User: [email protected] Show 0 Delegates
User: [email protected] Show 1 Delegate
Delegate: [email protected]
Status: acceptedUser: [email protected] Show 2 Delegates
Delegate: [email protected] (1/2)
Status: acceptedDelegate: [email protected] (2/2)
Status: acceptedUser: [email protected] Show 0 Delegates
Here is an out put from Variable B :
group : [email protected]
type : USER
role : OWNER
status : ACTIVE
email : [email protected]group : [email protected]
type : USER
role : MANAGER
status : ACTIVE
email : [email protected]group : [email protected]
type : USER
role : MANAGER
status : ACTIVE
email : [email protected]group : [email protected]
type : USER
role : OWNER
status : ACTIVE
email : [email protected] -
January 13, 2021 at 1:33 pm #285664
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.
PowerShell123456789101112131415161718192021222324252627282930$variableA = @'User,Delegate,Status[email protected],[email protected],accepted[email protected],[email protected],accepted[email protected],,accepted'@ | ConvertFrom-Csv$variableB = @'group,type,role,status,email[email protected],USER,OWNER,ACTIVE,[email protected][email protected],USER,MANAGER,ACTIVE,[email protected][email protected],USER,MANAGER,ACTIVE,[email protected][email protected],USER,OWNER,ACTIVE,[email protected]'@ | ConvertFrom-Csv$combined = foreach($entry in $variableA){$variableB | where email -eq $entry.user | ForEach-Object {[PSCustomObject]@{User = $entry.userDelegate = $entry.DelegateStatus = $entry.StatusGroup = $_.groupRole = $_.roleEmail = $_.email}}} -
January 14, 2021 at 1:54 pm #285787
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
-
-
AuthorPosts
- You must be logged in to reply to this topic.