Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Join hash tables / LINQ?

$
0
0

Hello,

I'm stuck at the following. I have three hash tables like this:

$a (from AD):

Name                         Value
----                         -----
ComputerName1                {ManagedBy, WhenChanged, DistinguishedName, Name...}
ComputerName2                {ManagedBy, WhenChanged, DistinguishedName, Name...}
ComputerName3                {ManagedBy, WhenChanged, DistinguishedName, Name...}
ComputerName4                {ManagedBy, WhenChanged, DistinguishedName, Name...}
...

$b (from SCCM):

Name                         Value
----                         -----
ComputerName1                {LastHWScan, Name, UserName}
ComputerName2                {LastHWScan, Name, UserName}
ComputerName3                {LastHWScan, Name, UserName}
ComputerName4                {LastHWScan, Name, UserName}
...

$c (from McAfee):

Name                         Value
----                         -----
ComputerName1                {LastUpdate, Name}
ComputerName2                {LastUpdate, Name}
ComputerName3                {LastUpdate, Name}
ComputerName4                {LastUpdate, Name}
...

I'm desperately looking for a way to join these hash tables so I get

Name                         Value
----                         -----
ComputerName1                {ManagedBy, WhenChanged, DistinguishedName, LastUpdate, LastHWScan, UserName}
ComputerName2                {ManagedBy, WhenChanged, DistinguishedName, LastUpdate, LastHWScan, UserName}
ComputerName3                {ManagedBy, WhenChanged, DistinguishedName, LastUpdate, LastHWScan, UserName}
ComputerName4                {ManagedBy, WhenChanged, DistinguishedName, LastUpdate, LastHWScan, UserName}
...

(Yes, I need to get rid of the name field in each hash table, because it is equal to the key. My ArrayTo-HashTable functions needs some tweaking).

The three hash tables each have about 20 000 objects, so I do not want to use a cascade of ForEach loops as this will take a long long time (20 000³ calculations, although in reality I'd break out of the loop on a hit). What I actually want to do is a SQL kind of FULL OUTER JOIN. I find zero information about this. The only thing I find for doing database-like actions in memory is with LINQ, but I read on several places that LINQ doesn't work with PoSh (although it is .NET) and even then I am missing information on how to implement it - the only examples I find are from other .NET languages (eg. C#).

I know about http://bartdesmet.net/blogs/bart/archive/2008/06/07/linq-through-powershell.aspx, but then I would need to use a custom DLL and that would make my script(s) less portable. Preferably I have no dependencies.

Does any see possibilities to handle large datasets without ForEach loops? Thank you in advance.


My grandmother always used to say: "::1: sweet ::1:"


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>