PS C:\Users\kris> $hashx=@{}
PS C:\Users\kris> $(Get-CimInstance Win32_Process | Select-Object ProcessId, Name) | ForEach-Object { $hashx[$_.ProcessId]=$_.Name }
PS C:\Users\kris> $hashx
Name Value
---- -----
1292 svchost.exe
6032 StartMenuExperienceHost.exe
428 smss.exe
4736 powershell.exe
2580 svchost.exe
5628 explorer.exe
5164 taskhostw.exe
PS C:\Users\kris> $hashx['5164']
PS C:\Users\kris> $hashx.5164
PS C:\Users\kris> $hashx."5164"
PS C:\Users\kris> $hashx.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Hashtable System.Object
Can anyone explain me what i do wrong? i'm beginner in powershell, and i don't understand why it returns null value by key?
$(Get-CimInstance -Query "SELECT * From Win32_Process WHERE ProcessId = '5164'").Nameto retireve the process Name assigned to that process ID, instead of creating a Hashtable.[uint32]. So you need to cast each key to that type-->$hashx[[uint32]5164].