Since you’re nesting (embedding)
" chars. – to be passed verbatim to PowerShell – inside the syntactic outer double-quoting (
"..."), you must escape those nested
Even though PowerShell-internally
` serves as the escape character, calling the PowerShell CLI (
pwsh) from the outside (
# Embedded " chars. must be \-escaped powershell -command "([ADSI]\"IIS://localhost/smtpsvc/1\").RelayForAuth -like \"*0*\""
Note that you can avoid the need for this escaping if you single-quote the strings inside the overall
While this works fine in your case, given that your strings have only verbatim content, note that this is generally only an option if no string interpolation is required:
# Embedded strings use '...' -> no escaping needed. powershell -command "([ADSI]'IIS://localhost/smtpsvc/1').RelayForAuth -like '*0*'"
Caveat: Using single-quoting to enclose the overall command (
'...') does not work as expected from
cmd.exe: the latter doesn’t recognize these as quoting, and PowerShell simply interprets the string as using its syntax for a verbatim string, and therefore simply prints the contents of the string.
For more information, see this answer.
CLICK HERE to find out more related problems solutions.