0

I want to add a task sequence, meaning the script will wait the first task to be finished first, then proceed with next task. If task receives error, it will not proceed and probably will create log for that.

WindowsSensor_F7C855810C3B47FC8931D2E5E9E889BF-57.exe /install /quiet /norestart

"%ProgramFiles%\CrowdStrike\CSInstallGuard.exe" PW="nzhHLfrpy5rqTFVsne8D"

if exist "%ProgramFiles%\Cylance\Desktop\CylanceSvc.exe" msiexec /x {2E64FC5C-9286-4A31-916B-0D8AE4B22954} /qn /norestart

Below is the code I come out. Can someone clean it up

Start-Process "WindowsSensor_F7C855810C3B47FC8931D2E5E9E889BF-57.exe" /install /quiet /norestart | Out-null

Start-Process "%ProgramFiles%\CrowdStrike\CSInstallGuard.exe" PW="nzhHLfrpy5rqTFVsne8D" | Out-null



if (test-path %ProgramFiles%\Cylance\Desktop\CylanceSvc.exe .PathType leaf){
    msiexec /x {2E64FC5C-9286-4A31-916B-0D8AE4B22954} /qn /norestart | Out-null
    }

    else {
    break

    }
  • Use the `-Wait` switch on `Start-Process` so the code only continues when the task is done. Use `$env:ProgramFiles` instead of `%ProgramFiles%` and combine the path's to use with [Join-Path](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/join-path?view=powershell-6). To run the msiexec with arguments, there are lots of examples to be found like for instance [this one](https://social.technet.microsoft.com/Forums/en-US/72405a6c-068e-4f7a-9989-dd3db63d5da9/how-to-add-these-arguments-in-msiexec-to-run?forum=winserverpowershell) – Theo Dec 20 '18 at 13:25

1 Answers1

0

You can pipe output like WindowsSensor_F7C855810C3B47FC8931D2E5E9E889BF-57.exe /install /quiet /norestart | Out-null This will make powershell to wait for the command to finish.

... actually I just retyped your question in the search bur and found similar ones with great answers, for example look at this question.

zura
  • 44
  • 6