I'm attempting to search a hash table that contains a hostname as the key and applications as the values. I'm looking for hostnames (keys) that do NOT contain a specific value AKA application. However, my code does not appear to work as I always receive all of the keys/hostnames back.
foreach ($global:computer in $global:hash.keys){
if ($global:hash.$global:computer.values -notcontains 'SnagIt'){
$global:computer
}
}
Example Data:
Key, Values
Host1:FireFox,Chrome,IE
Host2:Snagit,FireFox,Chrome,IE
Host3:Chrome,IE
Example Value Output from $global:hash.$global:computer:
{Snagit, FireFox, Chrome, IE...}
Hash Table Build Code:
$global:Csv = Import-Csv -LiteralPath $global:ConvertedSNWReport
[HashTable]$global:Hash=@{}
For ($i = 0; $i -lt ($global:Csv."Computer name").Count; $i++)
{
If ($global:Hash.ContainsKey($global:Csv[$i].'Computer name'))
{
$global:Hash.($global:Csv[$i].'Computer name').Application += $global:Csv[$i].Application
Continue
}
$global:Hash.($global:Csv[$i].'Computer name') = @{
Application = @($global:Csv[$i].Application)
}
}
.values[]) belongs after the list variable, not after the property, e.g.$global:Csv[$i].'Computer name'.$Hash.Computer.Applicationto get the array of programs for that PC.