ComputersUnlimited
IS-IT--Management
I have written a powershell script that executes CCleaner to clean the system drive of garbage files. As you most likely know for third party apps like CCleaner to clean internet cache, history etc for web-browsers the browsers need to be closed. So the first line in the script is
It works as expected and closes all active windows except for Powershell, however it doesn't close them fast enough before CCleaner starts. How can I pause the script until this line completes executing before continuing?
I have tried using wait-process as described in this link, however it is apparently won't work with the line above
I'd rather not use something to pause the script for X seconds, in case a user has a lot of open apps, one or more apps takes a while to close or it is just a slow system, I also don't want to pause the script any longer then necessary.
Anybody have any ideas or suggestions?
Code:
(get-process | ? { $_.mainwindowtitle -ne "" -and $_.processname -ne "powershell" } )| stop-process
It works as expected and closes all active windows except for Powershell, however it doesn't close them fast enough before CCleaner starts. How can I pause the script until this line completes executing before continuing?
I have tried using wait-process as described in this link, however it is apparently won't work with the line above
I'd rather not use something to pause the script for X seconds, in case a user has a lot of open apps, one or more apps takes a while to close or it is just a slow system, I also don't want to pause the script any longer then necessary.
Anybody have any ideas or suggestions?