The code below produce 2 "identical" Hashtables, however on the one that was grouped using a code block I can't get items from the key.
$HashTableWithoutBlock =
Get-WmiObject Win32_Service | Group-Object State -AsHashTable
$HashTableWithBlock =
Get-WmiObject Win32_Service | Group-Object {$_.State} -AsHashTable
Write-Host "Search result for HashTable without using code block : " -NoNewline
if($HashTableWithoutBlock["Stopped"] -eq $null)
{
Write-Host "Failed"
}
else
{
Write-Host "Success"
}
Write-Host "Search result for HashTable with code block : " -NoNewline
if($HashTableWithBlock["Stopped"] -eq $null)
{
Write-Host "Failed"
}
else
{
Write-Host "Success"
}
Output :
Search result for HashTable without using code block : Success
Search result for HashTable with code block : Failed
What is the difference between the two Hashtables ?
How to get Items on second one that was grouped by code block ?
EDIT : More than a workaround, I'd like to know if it is possible to retrieve the Item I want with a table lookup, and if yes, how ?