Change $null behavior to print out?

Take the following snippet

'a',$null,'b'

This is the result

a
b

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

Answers


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

[string[]]('a',$null,'b')

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 vb.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?