Change $null behavior to print out?

Take the following snippet


This is the result


Is there a way to change this default? So that null is actually treated in output as something.


There's no way to change that behaviour, but as a workaround you can do this:


to get the desired result.

This will turn the $null into a blank string:

'a',$null,'b' | % { "$_" }

Or you could transform the $null into some arbitrary string such as '[null]':

'a',$null,'b' | % { if ($_ -ne $null) {$_} else {'[null]'} }

Need Your Help

Is there an advantage to USING vs. declaring a context variable?

.net linq linq-to-sql

These two snippets do the same thing - is there one that's better than the other, or is it just a matter of preference?