Another frequently asked question about PowerShell/Exchange shell, and one that I myself had during the initial foray with the shell – what’s the difference between using double quotes and single quotes in a shell command or script?
The biggest difference, and the only one I’m aware of, is the fact that using double quotes – e.g. “$mailboxes”, expands the variable. (Note, if the variable has not been used/defined or doesn’t have any value, you get no output.)
When using single quotes – e.g. ‘$mailboxes’, it is treated as a string.
To see the difference in action:
$mailboxes = Get-Mailbox
Now that we have captured the value(s) of mailbox(es) in a variable (actually an array… it can have a single or multiple values. In this case, a single mailbox, if you only have one, or multiple mailboxes).
Next, let’s get some output from this. First, let’s try with single quotes:
Write-Host ‘This is a list of all my mailboxes: $mailboxes’
What you get is simply:
This is a list of all my mailboxes: $mailboxes
Now let’s try with double quotes:
Write-Host “This is a list of all my mailboxes: $mailboxes”
The output will list all your mailboxes, as seen below:
This is a list of all my mailboxes: Jane Doe John Doe….
I haven’t found any side-effects of using double-quotes, except when you really want a particular variable/string to be treated as a string.
{ 0 comments… add one now }