/build/static/layout/Breadcrumb_cap_w.png

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

  1. Verify that the file “C:\Program Files (x86)\ntusernoscript.txt” exists.
    trashcan-icon.png
Reorder | Add…

On Success

  1. Log “This ntusernoscript file found. NTuser.dat script not ran.” to “status”.
    trashcan-icon.png
Reorder | Add…

Remediation

Reorder | Add…

On Remediation Success

Reorder | Add…

On Remediation Failure

Reorder | Add…

Task 2trashcan-icon.png

Attempts: 
On Failure:  Break  Continue

Verify

  1. Verify that the directory “C:\Windows\System32\WindowsPowerShell\v1.0” exists.
    trashcan-icon.png
Reorder | Add…

On Success

  1. Launch “$(KACE_SYS_DIR)\WindowsPowerShell\v1.0\powershell.exe” with params “-executionpolicy remotesigned -File $(KACE_DEPENDENCY_DIR)\NTUSER_DATE_CHANGE.ps1”.
    trashcan-icon.png
Reorder | Add…

Remediation

  1. Log “Couldn't find powershell” to “status”.
    trashcan-icon.png
Reorder | Add…

On Remediation Success

  1. Log “Powershell script ran successfully.” to “status”.
    trashcan-icon.png
Reorder | Add…

On Remediation Failure

  1. Log “Powershell script failed.” to “status”.
    trashcan-icon.png
Reorder | Add…
plus-icon.pngNew Task…

0 Comments   [ + ] Show comments

Answers (3)

Answer Summary:
Posted by: lbruschuk 5 years ago
White Belt
1

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 5 years ago
Red Belt
0
Have you tried adding the second task into the first task as a remediation path, thereby removing the need for a second task?
Posted by: worzie 5 years ago
Fourth Degree Brown Belt
0
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.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ