Hello,
I am trying to figure out how to merge data to build a specific array that can be exported out to CSV. I have already reached the point where I can build the following array which provides all of the raw data that can be exported out to CSV.
$results = for ($i = 0; $i -lt $emailaddress.count; $i++) {
New-Object psobject -Property @{
EmailUser = $user[$i]
EmailDomain = $domain[$i]
EmailAddress = $emailaddress[$i]
Disposition = $disposition[$i]
Date = $date[$i]
Time = $time[$i]
}
}
What I am trying to do is make a second CSV that only lists each unique email address and the count for each disposition. So to start on that I created 5 different “arrays” of data that all have one common element “emailaddress” This was done by searching for each disposition and grouping them by email address giving a unique count for each disposition.
Here are the arrays in question:
$Total = for ($i = 0; $i -lt $Total.count; $i++) {
New-Object psobject -Property @{
'EmailAddress' = $Total[$i].Name
'Total' = $Total[$i].Count
}
}
$Tnone = for ($i = 0; $i -lt $Tnone.count; $i++) {
New-Object psobject -Property @{
'EmailAddress' = $Tnone[$i].Name
'None' = $Tnone[$i].Count
}
}
$Tspam = for ($i = 0; $i -lt $Tspam.count; $i++) {
New-Object psobject -Property @{
'EmailAddress' = $Tspam[$i].Name
'Spam' = $Tspam[$i].Count
}
}
$Topl = for ($i = 0; $i -lt $Topl.count; $i++) {
New-Object psobject -Property @{
'EmailAddress' = $Topl[$i].Name
'OPL' = $Topl[$i].Count
}
}
$Tgray = for ($i = 0; $i -lt $Tgray.count; $i++) {
New-Object psobject -Property @{
'EmailAddress' = $Tgray[$i].Name
'Gray' = $Gray[$i].Count
}
}
What I am trying to figure out is how to join all the data together to end up with a CSV that looks like:
Emailaddress, Total, None, Spam, OPL, Gray
Bob@example.com, 50, 30, 9, 10, 1
Tom@example.com, 72, 19, 21, 30, NULL
Sue@example.com, 3, 2, NULL, 1, NULL
Instead I am getting something like:
Emailaddress, Total, None, Spam, OPL, Gray
Bob@example.com, 50, NULL, NULL, NULL, NULL
Tom@example.com, 72, NULL, NULL, NULL, NULL
Sue@example.com, 3, NULL, NULL, NULL, NULL
Bob@example.com, NULL, 30, NULL, NULL, NULL
Tom@example.com, NULL, 19, NULL, NULL, NULL
Sue@example.com, NULL, 2, NULL, NULL, NULL
When I try to join them using:
$finaltotal = @() $finaltotal += $total | select EmailAddress,Total,None,Spam,OPL,Gray $finaltotal += $Tnone | select EmailAddress,Total,None,Spam,OPL,Gray $finaltotal += $tspam | select EmailAddress,Total,None,Spam,OPL,Gray $finaltotal += $topl | select EmailAddress,Total,None,Spam,OPL,Gray $finaltotal += $Tgray | select EmailAddress,Total,None,Spam,OPL,Gray
Any idea how to do this properly?