While catching up on blog comments while I was out I found on my blog post Reinventing the Wheel – Automating Data Consistency Checks with Powershell, a comment was posted by Grant regarding how I had concatenated the $ScriptName variable into the email subject line in the $subject variable.
Shouldn't the line
$subject = "$ScriptName returned results"
be
$subject = $ScriptName + " returned results"
In TQL, you would have to do a + based concatenation like Grant asked, but in Powershell, its not necessary. Take for example the following:
$string1 = "String1";
$string2 = "$String1 concatenated with String2";
Write-Host $string2;
The output will be:
String1 concatenated with String2
Does it really matter? No, its pretty semantic. You could also use the Format() method of the String Object in the .NET model to accomplish the same thing if you were so inclined:
$string1 = "String1";
$string2 = [String]::Format("{0} concatenated with String2", $string1);
Write-Host $string2;
There’s more than one way to skin a cat, at least so I am told, I’ve never skinned a cat in real life. I don’t know when I figured out that you can do direct placement of variables inside of strings and save key strokes, but a lot of my Powershell code is written with the variables inline to the text that they are being concatenated into like the subject line in the blog post mentioned above.