Consider the following XML document:
$xml = [xml] "<root><value>one</value><value>two</value></root>"
And then print the values (with some prefix/suffix):
$xml.root.value | %{"*$_*"}
*one*
*two*
So far so good. However, if the element does not exist, a null item is propagated trough the pipeline:
$xml.root.foo | %{"*$_*"}
**
Why is that? Is there any way to avoid this extra check:
$xml.root.foo | ?{$_} | %{"*$_*"}
It’s easy to forget and it seems error prone.
To turn off the silent fail on missing properties use
Set-StrictMode -Version Lateste.g.:Note that this will also catch references to non-existing variables. I highly recommend using
Set-StrictModein this manner as it can save you debugging time for larger scripts.