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

PowerShell创建SCCM应用部署类型:添加双检测方法报错求助

解决SCCM PowerShell创建ProductCode检测子句的问题

我之前也踩过这个参数集的坑!New-CMDetectionClauseWindowsInstaller有两组参数对应SCCM里的两个单选按钮,你要的“仅检测ProductCode存在”模式,必须明确指定-Exist参数才能让PowerShell识别正确的参数集,否则就会出现你遇到的参数解析错误。

正确创建仅检测ProductCode存在的子句

把你的$clause2改成下面的写法,就能成功创建检测子句了:

$clause2 = New-CMDetectionClauseWindowsInstaller -ProductCode $ProductCode -Exist

错误原因说明

你之前只指定-ProductCode时,PowerShell无法判断你是要检测产品存在,还是要检测版本匹配,所以触发了“The parameter set cannot be resolved”错误,导致$clause2返回NULL,后续执行Add-CMScriptDeploymentType时自然会报参数绑定失败的错误。

完整的示例代码

这里给你一套完整的流程,包含注册表检测+ProductCode存在检测的组合:

# 创建注册表检测子句
$clause1 = New-CMDetectionClauseRegistryKeyValue -Hive LocalMachine -KeyName "pathstuff" -Is64Bit -ValueName "aValue" -PropertyType String -ExpressionOperator IsEquals -ExpectedValue $aVar

# 创建ProductCode存在检测子句
$clause2 = New-CMDetectionClauseWindowsInstaller -ProductCode $ProductCode -Exist

# 将两个检测子句合并为数组
$detectionClauses = @($clause1, $clause2)

# 添加到脚本部署类型(替换成你的应用名称和部署类型名称)
Add-CMScriptDeploymentType -ApplicationName "你的应用名称" -ScriptContent "你的部署脚本内容" -DeploymentTypeName "你的部署类型名称" -AddDetectionClause $detectionClauses

这样就能同时添加两种检测方法,完全对应SCCM里的配置啦。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 08:07:43