我正在尝试处理许多应用程序,希望为部署添加新规则。从网上看,人们似乎已经成功地将规则从一个应用程序复制到另一个应用程序。我使用模板规则创建了模板应用程序和模板部署。
以下脚本是其他脚本的几乎未修改的示例。
$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
有趣的是,如果不添加新的需求规则,我可以将其放入并放置它。
有什么想法或建议吗?
答案 0 :(得分:0)
您要设置的规则有多复杂?如果仅是一条规则,您是否尝试过通过AddRequirement参数进行设置?:
Set-CMDeploymentType -ApplicationName $AppName -DeploymentName $DeploymentName -AddRequirement <rule>
在模板上进行处理,然后将其集成到数组中。
答案 1 :(得分:0)
我认为发布另一个答案会更清楚。我基本上已经遍历了我在评论中添加的链接中提到的内容,并且成功地将W10要求添加到了预先存在的部署中。这是我使用的代码:
.\Add-CMDeploymentTypeGlobalCondition.ps1 -ApplicationName $AppName -DeploymentTypeName $DeploymentName -sdkserver <servername> -sitecode <sitecode> -GlobalCondition "OperatingSystem" -Operator "OneOf" -Value "Windows/All_x64_Windows_10_Client"
答案 2 :(得分:0)
原始帖子帮助中的此脚本 并收到用户收到的错误-如果有人在SCCM中打开了应用程序,则可能导致此错误。
如果存在多种部署类型,则还需要将“ $ DestDeploymentTypeIndex = 0”增加+1。