Posts

Showing posts with the label Expansion

Powershell Strings and Expressions

Image
Today's topic? PowerShell, Strings, Variable Expansion and Quotes! Let's start with the difference between the single and double quotes. When using single quotes, the dollar sign within a string doesn't get treated as a special character so the text following it does not get resolved to the corresponding variable as opposed to the double quotes. The "file" variable in the following examples holds the output object of the Get-Item cmdlet. Variable expansion within strings... Let me start with an example. We have an object that has multiple properties and we want to create a string using the value of one of those properties. We have to use double quotes since we want the variable to be resolved but the result isn't the desired one.   This is because PowerShell will replace the variable with it's string representation and the property will be interpreted as text. This is where the PowerShell expressions come into play. Enclosing the variabl...