Don’t+Concatenate+Strings

    image045.png

    There’s a sub-gotcha here:

    This won’t work as expected. In most cases, $wmi will be replaced by an object type name, and .serialnumber will still be in there. That’s because . isn’t a legal variable name character, so PowerShell stops looking at the variable with the letter i. It replaces $wmi with its contents. You see, in the previous example, I’d put $($wmi.serialnumber), which is a subexpression, and which works. The parentheses make their contents execute as code.