I have a list of servers and each one has at least one email distribution list associated with it as a "stakeholder" we can contact for downtime etc.
When we do maintenance we email all the distribution lists of the implicated servers and there is duplication as many servers can all have the same one email contact (SERVER1, SERVER2). The other issue is that a single server could also have multiple email contacts (SERVER3), separated by a semicolon so they parse correctly when pasted into Outlook.
SERVER1 group1@somewhere.com SERVER2 group1@somewhere.com SERVER3 group1@somewhere.com ; group23@somewhereelse.com
Right now, from a big array from a spreadsheet, I do either a Get-Unique
:
$spreadsheetDataObject |
select contacts, patchcycle |
where {($_.patchcycle -eq "SpectreSat")} |
Sort-Object contacts |
select contacts |
Get-Unique
Or a -Unique off the
Sort-Objects`:
$spreadsheetDataObject |
select contacts, patchcycle |
where {($_.patchcycle -eq "SpectreSat")} |
Sort-Object contacts -Unique |
select contacts
And both get me the result:
group1@somewhere.com group1@somewhere.com ; group23@somewhereelse.com
I would like to know the best way to unique "everything" so that the second line separated by the semi-colon would be split out and uniqued as well so the output looks like this:
group1@somewhere.com group23@somewhereelse.com
What's the best way to do this and in how many steps? Split any email addresses separated by semicolon first into unique array elements and remove the ;
(not sure how to do this) and then do a unique on the new array? Maybe a trim as well in case spaces are hiding around the ;
.