首页 > 解决方案 > 如何通过 New-CMDetectionClauseWindowsInstaller 将 Productcode 设置为检测方法

问题描述

我有一个 PowerShell 脚本,它创建具有部署类型的应用程序...我能够使用 New-CMDetectionClauseRegistryKeyValue 为注册表项创建一个检测方法

但我想要的是有两种检测方法。一个是注册表项,另一个是 ProductCode。

所以我这样做:

$clause1 = New-CMDetectionClauseRegistryKeyValue -Hive LocalMachine -KeyName "pathstuff" -Is64Bit -ValueName "aValue" -PropertyType String -ExpressionOperator IsEquals -ExpectedValue $aVar -Value
$clause2 = New-CMDetectionClauseWindowsInstaller -ProductCode $ProductCode

但是我收到第二个子句的错误:

无法使用指定的命名参数解析参数集

我相信之后我的行必须如下:

Add-CMScriptDeploymentType -ApplicationName $AppName -DeploymentTypeName $DepTypeName -ContentLocation $DepContentLocation -InstallCommand $DepInstallCommand `
            -UninstallCommand $DepUninstallCommand -AddDetectionClause $clause1,$clause2 -EstimatedRuntimeMins $DepMinRuntime -MaximumRuntimeMins $DepMaxRuntime `
            -LogonRequirementType WhetherOrNotUserLoggedOn -UserInteractionMode Hidden -InstallationBehaviorType InstallForSystem -AddRequirement $oDTRule

但我得到了错误

该参数不能绑定到 AddDetectionClause 参数,因为它是 NULL。

因为第2条不起作用...

我发现如果你这样做,它似乎可以工作:

$clause1 = New-CMDetectionClauseWindowsInstaller -ProductCode $guid [Value -ExpressionOperator IsEquals -ExpectedValue "1.1.1.1" # Do a version check

但这将是 SCCM 中的第二个 Radiobutton,我想要第一个。

我只是不知道我错过了什么。没有关于这个的文档......而且谷歌并没有给我太多......

任何帮助,将不胜感激。

问候

标签: powershellsccm

解决方案


这让我困扰了好几个星期,最后这只是 RTFM 的一个例子。因此,在此命令的 Microsoft Docs页面上是我无法阅读的答案。

$clause2 = New-CMDetectionClauseWindowsInstaller -ProductCode $ProductCode -Existence

你只需要把 -Existence 放在最后就可以了。

我非常专注于没有没有阅读完整语法描述的示例。


推荐阅读