How do I verify if a file exists and then stop the script from going to Task 2 if the file indeed exists?
Here's my current script. If the script detects the text file in the first verify, it continues on and completes the script. I need it to do the opposite and actually stop running Task 2. If the file does not exist, then I need it to move on to Task 2.
Verify
On Success
Remediation
Reorder | Add…
On Remediation Success
Reorder | Add…
On Remediation Failure
Reorder | Add…
Task 2
Attempts: | |
On Failure: | Break Continue |
Verify
On Success
- Launch “$(KACE_SYS_DIR)\WindowsPowerShell\v1.0\powershell.exe” with params “-executionpolicy remotesigned -File $(KACE_DEPENDENCY_DIR)\NTUSER_DATE_CHANGE.ps1”.
Reorder | Add…
Remediation
On Remediation Success
On Remediation Failure
New Task…
0 Comments
[ + ] Show comments
Answers (3)
Answer Summary:
Please log in to answer
Posted by:
lbruschuk
6 years ago
Top Answer
On the machines I did not want this script to run I unzipped a file to C:\Program Files (x86)\ntusernoscript.txt.
I then modified the start of my PowerShell script to search for that file and end immediately if that text file was located.
if (Test-Path "C:\Program Files (x86)\ntusernoscript.txt") {Exit 0}
Posted by:
Hobbsy
6 years ago
Posted by:
worzie
6 years ago
You don't say, but, in task 1, the attempts section, On Failure, Break or Continue should be set to break. Otherwise, yes, add task 2 to remediation if the behavior is continuing. Verifying for PS may not be necessary but you can add that to your task 1 verify too if you need.
I'm a little confused tho as you say you want it to continue to task 2 if task 1 verify fails. Regardless of my confusion, you could verify if the file doesn't exist as well and play that game.
Not all parts of the task fields need to be filled out either. They tend to be verbose enough without adding the log messages all the time. Good for learning what part of the script is doing something tho.