I would like to output variables and values out in a PowerShell script by setting up flags and seeing the data matriculate throughout the script.
How would I do this?
For example, what would be the PowerShell equivalent to the following PHP code?
echo 'filesizecounter: ' . $filesizecounter
There are several ways:
Write-Host: Write directly to the console, not included in function/cmdlet output. Allows foreground and background colour to be set.Write-Debug: Write directly to the console, if$DebugPreferenceset to Continue or Stop.Write-Verbose: Write directly to the console, if$VerbosePreferenceset to Continue or Stop.The latter is intended for extra optional information,
Write-Debugfor debugging (so would seem to fit in this case).Additional: In PSH2 (at least) scripts using cmdlet binding will automatically get the
-Verboseand-Debugswitch parameters, locally enablingWrite-VerboseandWrite-Debug(i.e. overriding the preference variables) as compiled cmdlets and providers do.