【问题标题】:Modify SCCM Application Deployment using Powershell fails使用 Powershell 修改 SCCM 应用程序部署失败
【发布时间】:2020-01-15 00:28:39
【问题描述】:

我正在尝试处理大量应用程序,希望在部署中添加新规则。从网上看,似乎人们已经成功地将规则从一个应用程序复制到另一个应用程序。我使用我的模板规则创建了一个模板应用程序和一个模板部署。

以下脚本是其他人使用的几乎没有修改的示例。

$SourceRuleName = "*"
$SourceApplicationName = "Template1"
$SourceDeploymentType = "Template DeploymentType"

$DestApplicationName = "Template2"
$DestDeploymentTypeIndex = 0

# get the applications
$SourceApplication = Get-CMApplication -Name $SourceApplicationName | ConvertTo-CMApplication
$DestApplication = Get-CMApplication -Name $DestApplicationName | ConvertTo-CMApplication

# get requirement rules from source application
$Requirements = $SourceApplication.DeploymentTypes[0].Requirements | Where-Object {$_.Name -match $RuleName}

# apply requirement rules
$Requirements | ForEach-Object {

    $RuleExists = $DestApplication.DeploymentTypes[$DestDeploymentTypeIndex].Requirements | Where-Object {$_.Name -match $RuleName}
    if($RuleExists) {

        Write-Warning "The rule `"$($_.Name)`" already exists in target application deployment type"

    } else{

        Write-Host "Apply rule `"$($_.Name)`" on target application deployment type"

        # create new rule ID
        $_.RuleID = "Rule_$( [guid]::NewGuid())"
        $DestApplication.DeploymentTypes[$DestDeploymentTypeIndex].Requirements.Add($_)
    }
}

# push changes
if($DestApplication.IsChanged){
    $Application = $DestApplication | ConvertFrom-CMApplication  
    $Application.Put()
}

看起来很简单,但它失败并出现以下错误。

Exception calling "Put" with "0" argument(s): "The SMS Provider reported an error."
At line:37 char:5
+     $Application.Put()
+     ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

有趣的是,如果我不添加新的需求规则,我可以获取应用程序并将其放入。

有什么想法或建议吗?

【问题讨论】:

  • 我不是 100% 确定,但我认为即使通过 powershell 完成,您也应该能够在站点服务器上的 smsprov.log 中看到更详细的错误。也许这可以帮助您更深入地了解问题

标签: powershell sccm


【解决方案1】:

您尝试设置的规则有多复杂?如果这只是一个规则,您是否尝试通过 AddRequirement 参数设置它?:

Set-CMDeploymentType -ApplicationName $AppName -DeploymentName $DeploymentName -AddRequirement <rule>

在模板上进行处理,然后将其集成到数组中。

【讨论】:

  • 我已经尝试过 AddRequirement,但找不到关于规则元素的任何文档。这就是我试图复制规则的原因。我需要的规则只是限制某些操作系统版本。
  • 我认为没有任何 MS 文档可以解决这个问题。您可能已经遇到过这个问题,但它显示了如何为需求创建 CM 对象。 gallery.technet.microsoft.com/Add-a-Requirement-to-an-ce60681f
【解决方案2】:

我认为发布另一个答案会更清楚。我基本上已经浏览了我在评论中的链接中提到的内容,并成功地将 W10 要求添加到预先存在的部署中。这是我使用的代码:

.\Add-CMDeploymentTypeGlobalCondition.ps1 -ApplicationName $AppName -DeploymentTypeName $DeploymentName -sdkserver <servername> -sitecode <sitecode> -GlobalCondition "OperatingSystem" -Operator "OneOf" -Value "Windows/All_x64_Windows_10_Client"

【讨论】:

    【解决方案3】:

    原始帖子帮助中的此脚本 用户收到错误 - 如果有人在 SCCM 中打开应用程序,可能会导致此错误。

    如果部署类型不止一种,“$DestDeploymentTypeIndex = 0”也需要增加+1。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 2016-10-20
      • 2018-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多