When do I need to surround strings in double quotes in PowerShell? Do I need all of these below?
& "$sendemail" -f "$sender" -t "$recipient" -u "$subject" -o message-file="$logpath" -s "$emailserver" -o tls=no
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In this case you need none.
$sendemailis hopefully already a string so the call operator&would work on it (maybe anything else would get coerced into a string anyway).All other variables should be passed correctly-quoted as well:
You would need quotes if you want to pass literal strings that contain special characters (e.g. shell operators or spaces) to a program, e.g.:
If all your arguments either do not contain such things or are already contained in a string variable themselves you’re good without quotes.