My PowerShell code is seeing the process run and every 60 seconds writes a message saying its running - that's working fine. When I kill the process it keeps writing the "process is running" every sixty seconds - when process has been eliminated. What is wrong with the logic that would not write an event in the App log - it works if I launch the script and the process is not running at the time of launch.
while($true) {
If (( $(Get-WmiObject Win32_Process |findstr "MoveFilesToServer") -eq $null ))
{
Write-EventLog -LogName Application -Source "MoveFilesToServer" -eventID 0018 -EntryType Error -Message "Move files process not running"
}
else { Write-Host 'process is running' }
Start-Sleep -Seconds 60
}