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

能否将注册表检测与Chrome安装PowerShell脚本合并?

合并PowerShell检测与Chrome安装脚本实现指定逻辑

当然可以合并两段脚本实现你要的逻辑,以下是完整的合并脚本:

# 遍历所有用户注册表分支,检测Google Chrome的卸载项
$chromeEntries = Get-ChildItem -Path 'Registry::HKEY_USERS\*\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome' -ErrorAction SilentlyContinue

# 统计已找到的注册表项数量
$entryCount = if ($chromeEntries) { $chromeEntries.Count } else { 0 }

# 当计数大于0时执行Chrome安装命令
if ($entryCount -gt 0) {
    # 启动msiexec执行静默安装,-Wait参数可等待安装完成后再继续脚本
    Start-Process -FilePath 'MsiExec.exe' -ArgumentList '/i "\\FileShare\NETLOGON\googlechromestandaloneenterprise64.msi" /qn ALLUSERS=1' -Wait
}

脚本说明:

  • Get-ChildItem用于扫描所有用户的注册表分支,-ErrorAction SilentlyContinue确保找不到目标项时不会抛出错误中断脚本
  • 通过判断返回结果是否存在,统计有效的注册表项数量
  • 使用Start-Process执行msiexec命令,相比直接调用更可控,-Wait参数可选,用于等待安装流程结束

注意:当前逻辑是检测到Chrome已存在时执行安装,这和常规的“未安装时部署”需求相反。如果是笔误,只需将if ($entryCount -gt 0)修改为if ($entryCount -eq 0),即可实现未安装Chrome时自动触发部署的逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 12:28:14