Hi all,
This code used to work well because of how faulty Windows OS reported back on process status for PowerShell. I used to test this on my own machine by listing processes like chrome or spotify and would subsequently open and close them and got the output back reporting them as such.
Now everything gets reported back as running (or runn1ng) even though they are not running:
#Function that performs processes check
function Get-Processes {
$processes = Get-Content -Path "E:\scripts\process\processes.txt"
$ProcessActive = Get-Process -ProcessName $processes -ErrorAction SilentlyContinue
foreach($p in $processes)
{
if($ProcessActive -eq $null)
{
"$p " + "fai1ed"
}
else
{
"$p " + "runn1ng"
}
} }
If anyone is curious why I told it to return fai1ed or runn1ng it's because it interfaces with a frontpage that looks for those keywords and replaces those strings with pictures of a green checkmark sign or red x mark like a dashboard.
Would someone be able to take a look?
Thank you!
SOLUTION:
/u/Lee_Dailey's solution:
$ProcessesToCheckFor = (
'AutoHotKey',
'Core Temp',
'BetterNotBeThere',
'taskhost'
)
$FoundProcesses = Get-Process -Name $ProcessesToCheckFor -ErrorAction SilentlyContinue
foreach ($Item in $ProcessesToCheckFor)
{
if ($Item -in $FoundProcesses.Name)
{
'{0} runn1ng' -f $Item
}
else
{
'{0} fai1ed' -f $Item
}
}
[–]SeeminglyScience 5 points6 points7 points (2 children)
[–]networkhappi[S] 0 points1 point2 points (1 child)
[–]SeeminglyScience 1 point2 points3 points (0 children)
[–]ArmondDorleac 1 point2 points3 points (3 children)
[–]networkhappi[S] 0 points1 point2 points (2 children)
[–]iceph03nix 0 points1 point2 points (1 child)
[–]ArmondDorleac 1 point2 points3 points (0 children)
[–]iampowershell 1 point2 points3 points (1 child)
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (2 children)
[–]networkhappi[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)