【发布时间】:2016-03-16 10:59:16
【问题描述】:
我们正在尝试使用 SCCM 2012 R2 对客户端运行一些检查并在需要时修复问题。为此,我们使用 PowerShell 'Script' 选项。
问题描述:
当“发现脚本”报告“不合规”时,会启动“补救脚本”。无论“修复脚本”的输出如何,“配置管理器 > 配置”中客户端报告的结果始终为“合规”,即使“修复脚本”未能修复问题并因此具有不同的输出然后在“合规条件规则”中定义。
似乎从选择“补救脚本”的那一刻起,SCCM 合规状态的输出始终是“合规”。
示例:
- 情况:
当文件夹“C:\Users\me\Downloads\Input_Test”中有文件或文件夹时,“发现脚本”会报告“不符合任何内容”并启动“修复脚本”。补救脚本采取行动但无法解决问题,因此它会报告除“合规”之外的其他内容,例如“不合规”。在执行“补救脚本”后,SCCM 合规状态应该说:“不合规”(事实并非如此)。
- PowerShell 发现脚本:
$Paths = Get-ChildItem -Path 'C:\Users\me\Downloads\Input_Test' | Select -ExpandProperty FullName
New-EventLog -LogName Application -Source SCCMCompliance
if ($Paths) {
$Compliance = 'Non-Compliant'
Write-EventLog -LogName Application -Source SCCMCompliance -EntryType Warning -EventID 1 -Message “Discovery script: Non-Compliant”
}
else {
$Compliance = 'Compliant'
Write-EventLog -LogName Application -Source SCCMCompliance -EntryType Information -EventID 0 -Message “Discovery script: Compliant”
}
$Compliance
- PowerShell 修复脚本:
Write-Output 'Non-Compliant'
Write-EventLog -LogName Application -Source SCCMCompliance -EntryType Warning -EventID 1 -Message “Remediation script: Non-Compliant $Paths”
在 Windows 事件查看器中,可以轻松跟踪所有步骤。我在这里遗漏了一些非常明显的东西吗?
【问题讨论】:
标签: powershell sccm