Hi, I would like to ask for your assistance in creating a script to find and remove two unwanted files on our Workstations. I can use a one liner using G-tchilditem -Recurse and then Remov-item. but I’ve realized that I need to add a bit more logic so the script only executes if the result of the Select-string-paten is not a successful $lastExitCode “0”.
$filea = C:\users\ * (This file can exist anywhere within a users profile.)
$Fileb = C:* (This file can exist anywhere in the C Drive)
$checkfile = C:\apps\Checkfile.txt
1 The first time the script will execute with no porbome because there is no check file.
2 On subsequent times the script would need to read the contents of the checkfile.txt select-string -pattern “0”
3. The Remove-Item command would execute and the check file would be created with Add-content $lastexitCode
My problem is developing the logic to determine whether the script needs to run or no t based on the content of the checkfile.txt.
Would I use the Test-path to determine the existence of the Checkfile?
Hopefully I am making sense.