all. I'm currently working on a script that is to do two things, both are pretty much the same.
The main priority is to have this script as the first thing running on startup and run a separate script that is made to open msedge.exe. My issue is that I need it to run once and pause after implementing the script and monitor for when msedge.exe is close accidentally or purposefully. When msedge.exe is stopped, the script will restart and open the separate script again.
Here's what I have. So far in the while loop, it does as intended, but starts the separate script every 5 seconds for when msedge.exe is not found running. I need it to basically stop there once and not run another instance of it until the parameter of msedge.exe running has been met and closed again, same for the script itself(that's the second thing). I think I'm doing this in the wrong way, so if anyone can help give advice, that would be great!
$edge = Get-Process | Where-Object -Property MainWindowTitle | where {$_.ProcessName -eq 'msedge'}
while ($true) {
if (!($edge)){
Start-Process "C:\Temp\SAPTestScripting.ps1"
sleep -Seconds 5
}
}
Make the Get-Process
-based test for the presence of a visible Edge process part of your loop.
while ($true) {
if (-not (
Get-Process -ErrorAction Ignore msedge |
Where-Object MainWindowTitle
)) {
# No visible Edge process? -> Restart.
Start-Process "C:\Temp\SAPTestScripting.ps1"
}
Start-Sleep -Seconds 5
}