Skip to content
Raymond Piller edited this page Jan 12, 2023 · 8 revisions

The following proxy functions will log anything sent to those proxy functions while keeping the original funtionality of those functions in tact. Keep in mind, that some messaging will only be logged if it would have been outputted to the screen. This is configured with the Preference Variables. So, if you want to see verbose messages, be sure to set $VerbosePreference to Continue.

⚠: Do not get in the habit of using -Silent or -Log parameters on proxy function calls. The point of PSWriteLog is that the script can be run on a system without PSWriteFunction installed without causing issues. Adding those parameters to a function call, will cause a parameter cannot be found that matches parameter name 'Silent' error. However, using $PSDefaultParameterValues to define parameters that do not exist are not an issue with PowerShell; even with strict mode enabled.

Write-Debug

  • Logging requires $DebugPreference to not be set to SilentlyContinue.
  • Prevent output to console: $PSDefaultParameterValues.Add('Write-Debug:Silent', $true); do not get in the habit of doing Write-Debug -Silent.
  • If you look at the code, you'll notice a NoLog parameter; this is for internal use to prevent looping. Don't use it!

⚠: Do not get in the habit of using -Silent parameters on proxy function calls.

Write-Error

  • Prevent output to console: $PSDefaultParameterValues.Add('Write-Error:Silent', $true); do not get in the habit of doing Write-Error -Silent.

⚠: Do not get in the habit of using -Silent parameters on proxy function calls.

Write-Host

  • Prevent output to console: $PSDefaultParameterValues.Add('Write-Host:Silent', $true); do not get in the habit of doing Write-Host -Silent.

⚠: Do not get in the habit of using -Silent parameters on proxy function calls.

Write-Information

  • Logging requires $InformationPreference; PowerShell 5.0+ to not be set to SilentlyContinue.
  • Prevent output to console: $PSDefaultParameterValues.Add('Write-Information:Silent', $true); do not get in the habit of doing Write-Information -Silent.

⚠: Do not get in the habit of using -Silent parameters on proxy function calls.

Write-Output

  • Logging requires $PSDefaultParameterValues.Add('Write-Output:Log', $true); do not get in the habit of doing Write-Output -Log.

⚠: Do not get in the habit of using -Log parameters on proxy function calls.

Write-Progress

  • We try to capture all of the progress information.

Write-Verbose

  • Logging requires $VerbosePreference to not be set to SilentlyContinue.
  • Prevent output to console: $PSDefaultParameterValues.Add('Write-Verbose:Silent', $true); do not get in the habit of doing Write-Verbose -Silent.

⚠: Do not get in the habit of using -Silent parameters on proxy function calls.

Write-Warning

  • Logging requires $WarningPreference to not be set to SilentlyContinue.
  • Prevent output to console: $PSDefaultParameterValues.Add('Write-Warning:Silent', $true); do not get in the habit of doing Write-Warning -Silent.

⚠: Do not get in the habit of using -Silent parameters on proxy function calls.

Clone this wiki locally