I’m trying to figure out why my while loop never exits:
This script waits for a Window Scheduled Task to no longer exist and then it should exit the loop, but it is waiting even though I go in and delete the Scheduled Task.
taskExists gets assigned a value once, before the loop therefore it always has a value. while($taskExists) will always evaulate to true. You need some type of condition within the loop that, under one or more conditions, will set the value of $taskExists to $null otherwise you get your infinite loop.
Since you basically already have a valid way to check I would suggest a do while loop
$taskName = "Remove EPM-agent"
do {
Start-Sleep -Seconds 10
$task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
} while ($task)
exit
In my script near the end it calls my function called “IsComplete” which checks for the existence of folders and writes to the log accordingly … writing to the log is another function.
So I have “IsComplete” called and after that the copy log logic. It never seems to get to the copying of the logs.
Here is “IsComplete” and after is the copy log logic.
WriteLog "Uninstaller was unable to remove all LANDesk folders. Please disable any security applications and try again or manually remove the LANDesk folders. "
}
WriteLog "Uninstaller was unable to remove all Ivanti folders. Please disable any security applications and try again or manually remove the LANDesk folders. "
}
Else{
WriteLog “Uninstaller was unable to remove all product folders. Please disable any security applications and try again.”
Please help us helping you. It is hard to distinguish between prosa and code when you don’t format your code properly.
So please go back, edit your posts once again and fix the formatting of your code.
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
I’d suggest starting a new thread for a new question. It can be super confusing following chains where lots of folk are participating trying to assist, and sometimes adding a new question a) causes additional confusion and b) won’t get the visibility because its a question under an existing thread.