Recently, I have been doing some script automation and found a very interesting thing, as shown below. If the user account contains the $ symbol, an exception "user cannot be found" will be thrown.
New-spsite $ communityurl-owneralias "asiapacific '\ $ exsquaredev001"-name "$ communityname"-template "STS #0"-contentdatabase $ communitydatabase
New-spsite: user cannot be found.
I searched on msdn and found an articleArticleAbout this: http://technet.microsoft.com/en-us/library/ff730965.aspx
Quotation marks in Windows powershell
First, let's review the basic distinction between Single and Double quotation marks in the Windows powershell language. It concerns the interpretation of variables.
Double quotes. When a command or expression that contains des variables is enclosed in double quotes ("), the variables are replaced by their values before the command is executed.
Single quotes.When a command or expression that contains des variables is enclosed in single quotes ('), the variables are not replaced by their values. Instead, they are interpreted literally.
There's actually a lot more to it-nested quotes and doubled quotes and escaped quotes and quotes in here-strings -- but these are the basics. for the rest, at the windows powershell prompt, type:
Because $ is the symbol of the powershell variable, different quotation marks are processed differently.
The powershell variable in double quotation marks is calculated first and then output.
Powershell variables in single quotes are directly output as strings.
See the following example:
Use double quotation marks to assign values,
Variable assignment: $ exsquareserviceaccount = "asiapacific \ $ exsquaredev001"
Output variable value: asiapacific \
Because the variable is recognized later, and no value is assigned, it is null at this time, and the output is the previous string.
If you use single quotes,
Variable assignment: $ exsquareserviceaccount = 'asiapacpacific \ $ exsquaredev001'
Output variable value: asiapacific \ $ exsquaredev001
The entire string will not be replaced with variables and will be output directly.