The actual debug output is written using the Write-Debug cmdlet within the script. Whether the debug output is written or not is governed by two things:
- Using the DebugPreference automatic variable. This variable resets itself to SilentlyContinue for each session. SilentlyContinue will make the script go on without the debug output being displayed. Setting the DebugPreference to Continue would change this behavior and display the debug output.
- Converting a function into an advanced function by simply declaring CmdletBinding(). This way, you would be able to easily control the debug display using the Debug switch. Whenever you need the debug display, simply call the function with the Debug switch; during the other times, ...