Skip to content

$cs.Job_DisableLog

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.

$cs.Job_DisableLog(string text = null)

Optional text to write to the log once, before logging is switched off. If omitted, nothing is logged.

None

Suppress logging around a single check that would otherwise write a noisy “not found” entry:

Terminal window
$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:

Terminal window
$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:

Terminal window
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")
}

$cs.Job_EnableLog