Exchange shell: Using double quotes or single quotes in commands or scripts
Posted by Bharat Suneja at 1:53 PM
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-MailboxNow 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: $mailboxesNow 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.