$cs.Job_DisableLog
Description
Section titled “Description”Turns off logging for all subsequent calls, until $cs.Job_EnableLog is called. Commonly used to suppress noisy or expected-to-fail log entries around a single check.
Syntax
Section titled “Syntax”$cs.Job_DisableLog(string text = null)
Parameters
Section titled “Parameters”text (String)
Section titled “text (String)”Optional text to write to the log once, before logging is switched off. If omitted, nothing is logged.
Return value
Section titled “Return value”None
Example
Section titled “Example”Suppress logging around a single check that would otherwise write a noisy “not found” entry:
$cs.Job_DisableLog("Temporarily disabling logging while checking for optional component")$installed = $cs.MSI_IsMSIGuidInstalled('{AC76BA86-1033-FF00-7760-BC15014EA700}')$cs.Job_EnableLog("Re-enabling logging")Suppress logging around a loop that probes several optional features, each of which is expected to fail for most machines:
$cs.Job_DisableLog("Silencing log while probing optional Windows features")$optionalFeatures = @("TFTP", "TelnetClient", "SNMP")$installedFeatures = foreach ($feature in $optionalFeatures) { $state = Get-WindowsOptionalFeature -Online -FeatureName $feature -ErrorAction SilentlyContinue if ($state -and $state.State -eq 'Enabled') { $feature }}$cs.Job_EnableLog("Finished probing optional features: $($installedFeatures -join ', ')")Wrap the suppressed section in try/finally so logging is guaranteed to be re-enabled even if the check throws an unexpected error:
try { $cs.Job_DisableLog("Silencing log while checking for a flaky optional dependency") $installed = $cs.MSI_IsMSIGuidInstalled('{AC76BA86-1033-FF00-7760-BC15014EA700}')} finally { $cs.Job_EnableLog("Re-enabling logging")}