【发布时间】: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