【问题标题】:How to add like a loop or if else statement to do the task 1 by 1如何添加循环或 if else 语句以逐个执行任务
【发布时间】:2018-12-20 02:06:16
【问题描述】:

我想添加一个任务序列,这意味着脚本将首先等待第一个任务完成,然后继续执行下一个任务。如果任务收到错误,它将不会继续,并且可能会为此创建日志。

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

下面是我出来的代码。有人可以清理一下吗

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

    }

【问题讨论】:

  • 使用-Wait 开关Start-Process 这样代码只有在任务完成后才会继续。使用$env:ProgramFiles 而不是%ProgramFiles% 并将路径与Join-Path 结合使用。要使用参数运行 msiexec,可以找到很多示例,例如 this one

标签: powershell software-distribution sccm


【解决方案1】:

你可以像管道输出一样 WindowsSensor_F7C855810C3B47FC8931D2E5E9E889BF-57.exe /install /quiet /norestart | Out-null 这将使 powershell 等待命令完成。

...实际上我只是在搜索 bur 中重新输入了您的问题,并找到了具有很好答案的类似问题,例如查看 this question.

【讨论】:

  • 嗨。我已经编辑了代码。你能在我的主要问题上检查一下吗?谢谢
  • 您正在混合两种替代方法:要么使用 |带有-wait选项的Start-process的out-null,但不是两者都
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-15
  • 1970-01-01
  • 2020-03-20
  • 2015-10-28
  • 2017-02-17
  • 2015-11-08
  • 1970-01-01
相关资源
最近更新 更多