You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在SCCM检测脚本中启动独立PowerShell实例以避免检测干扰?

解决SCCM检测脚本中运行AdobeUninstaller.exe的输出干扰问题

核心问题拆解

你需要在SCCM检测脚本中独立运行AdobeUninstaller.exe --list并保存输出,同时避免该程序的输出污染检测脚本的StdOut,导致SCCM误判检测结果。

具体解决方案

1. 直接独立运行AdobeUninstaller并重定向输出

无需嵌套调用PowerShell,直接用Start-Process调用目标程序,通过重定向输出隔离检测脚本的流:

# 替换为实际路径
$uninstallerPath = "C:\Program Files (x86)\Adobe\Adobe Creative Cloud\Utils\AdobeUninstaller.exe"
$outputLog = "C:\Windows\Temp\Adobe_Installed_Apps.log"
$errorLog = "C:\Windows\Temp\Adobe_Uninstaller_Errors.log"

# 确保输出目录存在
if (-not (Test-Path (Split-Path $outputLog))) {
    New-Item (Split-Path $outputLog) -ItemType Directory -Force | Out-Null
}

# 独立运行程序,完全隔离输出流
Start-Process -FilePath $uninstallerPath -ArgumentList "--list" `
    -RedirectStandardOutput $outputLog `
    -RedirectStandardError $errorLog `
    -Wait -NoNewWindow
  • -NoNewWindow:适配SCCM后台执行,避免弹出窗口
  • -RedirectStandardError:捕获错误输出,方便排查问题
  • -Wait:确保程序执行完成后再进行后续检测逻辑

2. 调用独立脚本的正确姿势(如需拆分逻辑)

如果必须通过独立脚本执行,需适配SCCM系统账户的执行环境:

Start-Process -FilePath "powershell.exe" -ArgumentList @(
    "-ExecutionPolicy", "Bypass",
    "-NoProfile",
    "-File", "C:\somefolder\somescript.ps1"
) -Wait -NoNewWindow
  • -NoProfile:避免加载用户配置文件,减少执行干扰
  • -ExecutionPolicy Bypass:解决系统账户下的脚本执行权限限制(根据环境调整)

3. 验证进程独立性

若需确认程序在独立进程运行,可添加进程检查:

$adobeProc = Get-Process -Name "AdobeUninstaller" -ErrorAction SilentlyContinue
if ($adobeProc) {
    Write-Host "AdobeUninstaller running in PID: $($adobeProc.Id)"
}

4. 检测脚本最终逻辑示例

输出保存后,读取日志文件判定检测结果:

$installedApps = Get-Content $outputLog -ErrorAction SilentlyContinue
if ($installedApps -match "目标Adobe软件名称") {
    # SCCM检测成功返回0
    exit 0
} else {
    # SCCM检测失败返回1
    exit 1
}

关键注意事项

  • 权限:确保输出目录(如C:\Windows\Temp)对系统账户有读写权限
  • 路径准确性:提前确认AdobeUninstaller.exe的实际安装路径,可通过Get-ChildItem在目标机器上定位
  • 流隔离:所有程序输出必须通过文件重定向处理,禁止直接流入检测脚本的StdOut

内容的提问来源于stack exchange,提问作者Tony W

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 08:00:39