tests/Test-CmComponentErrorSolutions.ps1
function Test-CmComponentErrorSolutions { [CmdletBinding()] param ( [parameter()][string] $TestName = "Test-CmComponentErrorSolutions", [parameter()][string] $TestGroup = "operation", [parameter()][string] $Description = "Get component error solutions", [parameter()][hashtable] $ScriptParams ) try { $startTime = (Get-Date) [int] $DaysBack = Get-CmHealthDefaultValue -KeySet "configmgr:ComponentErrorsMaxDaysOld" -DataSet $CmHealthConfig [System.Collections.Generic.List[PSObject]]$tempdata = @() # for detailed test output to return if needed $stat = "PASS" # do not change this $except = "WARNING" $msg = "No issues found" # do not change this either $query = "SELECT DISTINCT stat.Component, stat.MessageID, stat.MessageID AS Value FROM vStatusMessages AS stat where stat.Severity IN (-1073741824, -2147483648) AND stat.Component NOT IN ('Advanced Client', 'Windows Installer SourceList Update Agent', 'Desired Configuration Management', 'Software Updates Scan Agent', 'File Collection Agent', 'Hardware Inventory Agent', 'Software Distribution', 'Software Inventory Agent') AND stat.Time >= DATEADD(dd,-CONVERT(INT,$($DaysBack)),GETDATE())" $res = Get-CmSqlQueryResult -Query $query -Params $ScriptParams if ($null -ne $res -and $res.Count -gt 0) { $stat = $except $msg = "$($res.Count) items found within the last $DaysBack days" $res | Foreach-Object {$tempdata.Add($_.Component)} } } catch { $stat = 'ERROR' $msg = $_.Exception.Message -join ';' } finally { $rt = Get-RunTime -BaseTime $startTime Write-Output $([pscustomobject]@{ TestName = $TestName TestGroup = $TestGroup TestData = $tempdata Description = $Description Status = $stat Message = $msg RunTime = $rt Credential = $(if($ScriptParams.Credential){$($ScriptParams.Credential).UserName} else { $env:USERNAME }) }) } } |