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.
Is it possible in ISE to list all the variables in the script and their values?
And not show the default variables
Run "Get-Variable" as you open up the ISE and save the result to a variable, then when you want to check new variables you can run it again, but exclude the values you originally had.
$DefaultVariables=Get-Variable
Get-Variable -Exclude ($DefaultVariables.Name + "DefaultVariables")
Yes it is.
You can also just install and use the ISE addon on Variable Explorer. It's ion the Add-on menu.
Click Add-Ons, click 'Open Add-ons tools site', scroll down the page and select the 'ISE Variable Explorer' or get it straight from the MS PowershellGallery.com
PowerShell ISE VariableExplorer
This module makes quite easy to browse through all variable of the current PowerShell session.
https://gallery.technet.microsoft.com/PowerShell-ISE-VariableExpl-fef9ff01
Echo equivalent in PowerShell for script testing - Stack Overflow
Outputting variable value
Variables for Input(s) and output
how to see value of a variable in powershell - Stack Overflow
Videos
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.
Powershell has an alias mapping echo to Write-Output, so you can use:
echo "filesizecounter : $filesizecounter"
ls variable:* should work, or Get-Variable. If these are resulting in bad output, it's due to a poorly-implemented host, not with powershell itself. If you open the standard console host (run powershell.exe), you will see that these work fine.
If you need to work around a bad host, you might have better luck dumping everything to explicit strings:
Get-Variable | Out-String
or
Get-Variable |%{ "Name : {0}`r`nValue: {1}`r`n" -f $_.Name,$_.Value }
Interestingly, you can just type variable, and that works too!
I figured this out because I was curious as to what ls variable:* was doing. Get-Help ls tells us that it's an alias for PowerShell's Get-ChildItem, which I know will list all of the children of an Object. So, I tried just variable, and voila!
Based on this and this, it seems that what ls variable:* is doing is telling it to do some sort of scope/namespace lookup using the * (all/any) wildcard on the variable list, which, in this case, seems extraneous (ls variable:* == ls variable: == variable).