@Olaf’s answer provides a solution as it creates a hash table. But I enjoy these sorts of puzzles as they can provide experience.
@john-curtiss - I believe the error you received is due to hash tables using name/value pairs as the index, unlike arrays which use sequential numbers. You might have duplicates in either your source or transformed data.
My curiosity was also piqued by $entry.fqdn
. This indicates that $list
is already in some form of collection like [DataTable]
. And so, thinking outside the box, I created a 6x2 box for the source data. Then I put a subset of those data into a dictionary object where the key is the fqdn URI. The value in each row is dns which can be described as “type” or some such metadata later.
Subtext: use fqdn as the unique key in a collection. Extract the keys based on the generalized value.
Dictionary versus hash table discussions litter the internet. I like using dictionaries as they are well structured and should beat a hash table in data retrieval when sizes grow large
As for the multidimensional array list
, I like MDAs for well-structured data because of the way the data are stored. And, since the indexes are integers, you can get funky with data storage using loops. --When I squint (really squint) at MDAs, I see T-SQL’s hierarchyid
and FOR XML EXPLICIT
.
<#
Key is unique; use FQDN as URI.
Shape:
key value
------------
<fqdn> 'dns'
<fqdn> 'dns'
<fqdn> 'dns'
<fqdn> 'dns'
<fqdn> 'dns'
#>
using namespace System.Collections.Generic;
using namespace System.Data;
$list = [string[,]]::new(6,2); # 6 rows, 2 columns;
$list[0,0] = 'AutoDiscover';
$list[0,1] = 'autodiscover.domain.com';
$list[1,0] = 'ActiveSync';
$list[1,1] = 'activesync.domain.com';
$list[2,0] = 'Mail Services';
$list[2,1] = 'mailservices.domain.com';
$list[3,0] = 'om-xchangca';
$list[3,1] = 'om-xchangca.domain.com';
$list[4,0] = 'owa';
$list[4,1] = 'owa.domain.com'
$list[5,0] = '<none>';
$list[5,1] = 'domain.com';
$thiscertSANs = [Dictionary[string,string]]::new();
for($i = 0;$i -lt $list.GetUpperBound(0); $i++)
{
$thiscertSANs.Add("$($list[$i,1])",'dns');
}
## Results
cls;
$thiscertSANs; # or $thiscertSANs.GetEnumerator();
echo "`n`n";
($thiscertSANs.Keys).Where({$thiscertSANs.Values -eq 'dns'});
Results