Echo equivalent in PowerShell for script testing
Solution 1:
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 $DebugPreference
set to Continue or Stop.
Write-Verbose
: Write directly to the console, if $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.
Solution 2:
Powershell has an alias mapping echo
to Write-Output
, so you can use:
echo "filesizecounter : $filesizecounter"
Solution 3:
PowerShell interpolates, does it not?
In PHP
echo "filesizecounter: " . $filesizecounter
can also be written as:
echo "filesizecounter: $filesizecounter"
In PowerShell something like this should suit your needs:
Write-Host "filesizecounter: $filesizecounter"
Solution 4:
Write-Host "filesizecounter : " $filesizecounter