Echo equivalent in PowerShell for script testing
Echo equivalent in PowerShell for script testing
Echo equivalent in PowerShell for script testing
Re: Echo equivalent in PowerShell for script testing
There are several ways:
[`Write-Host`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-host): Write directly to the console, not included in function/cmdlet output. Allows foreground and background colour to be set.
[`Write-Debug`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-debug): Write directly to the console, if [`$DebugPreference`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables#debugpreference) set to Continue or Stop.
[`Write-Verbose`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-verbose): Write directly to the console, if [`$VerbosePreference`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables#verbosepreference) set to Continue or Stop.
The latter is intended for extra optional information, `Write-Debug` for debugging (so would seem to fit in this case).
**Additional**: In PSH2 (at least) scripts using cmdlet binding will automatically get the `-Verbose` and `-Debug` switch parameters, locally enabling `Write-Verbose` and `Write-Debug` (i.e. overriding the preference variables) as compiled cmdlets and providers do.
[`Write-Host`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-host): Write directly to the console, not included in function/cmdlet output. Allows foreground and background colour to be set.
[`Write-Debug`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-debug): Write directly to the console, if [`$DebugPreference`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables#debugpreference) set to Continue or Stop.
[`Write-Verbose`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-verbose): Write directly to the console, if [`$VerbosePreference`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables#verbosepreference) set to Continue or Stop.
The latter is intended for extra optional information, `Write-Debug` for debugging (so would seem to fit in this case).
**Additional**: In PSH2 (at least) scripts using cmdlet binding will automatically get the `-Verbose` and `-Debug` switch parameters, locally enabling `Write-Verbose` and `Write-Debug` (i.e. overriding the preference variables) as compiled cmdlets and providers do.