I'm trying to run on a list of processes and if found put the process name in hashtable with value True and if not False, the True part works just fine I got an issue if the process is not found it won't pair the searched process name with Flase just be blank
CODE
$processStatus = $null
$processStatus = @{}
$processName = "firefox", "discord", "fgdfg"
[System.Diagnostics.Process[]]$processList = Get-Process $processName -ErrorAction SilentlyContinue |
Sort-Object -Property name -Unique
ForEach ($process in $processList) {
if($process -ne $null) {
$processStatus.Add($process.ProcessName,"True")
} else {
$processStatus.Add($process,"Flase")
}
}
Result
Name Value
---- -----
Discord True
firefox True
Expected result
Name Value
---- -----
Discord True
firefox True
fgdfg False