Search code examples
powershellsoftware-distributionsccm

How to add like a loop or if else statement to do the task 1 by 1


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

    }

Solution

  • 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.