我正在尝试使用以下命令检查Windows SMTP服务器的RelayForAuth设置。 Powershell似乎显示正确的结果“ False”,但通过命令提示符运行同一命令时,会生成错误:
Powershell示例:
([ADSI]"IIS://localhost/smtpsvc/1".RelayForAuth -like "*0*")
输出:
False
命令提示符示例:
powershell -command "([ADSI]"IIS://localhost/smtpsvc/1".RelayForAuth -like "*0*")"
输出:
At line:1 char:8
+ ([ADSI]IIS://localhost/smtpsvc/1.RelayForAuth -like *0*)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'IIS://localhost/smtpsvc/1.RelayForAuth' in expression or
statement.
At line:1 char:8
+ ([ADSI]IIS://localhost/smtpsvc/1.RelayForAuth -like *0*)
+ ~
Missing closing ')' in expression.
At line:1 char:56
+ ([ADSI]IIS://localhost/smtpsvc/1.RelayForAuth -like *0*)
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [],
ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
答案 0 :(得分:2)
由于您是嵌套(嵌入)const validationSchema = object({
sending_country: object({
name: string().ensure().required().max(100, "Name too long")
}),
receiving_country: object().shape({
name: string().ensure().required().max(100, "Name too long")
}).when(
"sending_country", (sending_country, schema) => {
return schema.test({
test: receiving_country => receiving_country.name !== sending_country.name,
message: "Both countries cannot be identical"
})
})
})
个字符。-要在内将 verbatim 传递给PowerShell- em> syntactic 外部双引号("
),您必须转义 那些嵌套的"..."
字符。
即使PowerShell- 内部 "
用作转义符,从以下位置调用PowerShell CLI(`
/ powershell.exe
)外部(pwsh
)要求cmd.exe
转义\
:
"
请注意,如果您对单个# Embedded " chars. must be \-escaped
powershell -command "([ADSI]\"IIS://localhost/smtpsvc/1\").RelayForAuth -like \"*0*\""
字符串中的所有字符串进行 引用,则可以避免这种转义。。
尽管这在您的情况下很好用,但考虑到您的字符串仅包含 verbatim 内容,请注意,这通常仅是不需要string interpolation的选项:< / p>
"..."
注意事项:使用单引号将整个命令(# Embedded strings use '...' -> no escaping needed.
powershell -command "([ADSI]'IIS://localhost/smtpsvc/1').RelayForAuth -like '*0*'"
)括起来 不会按'...'
的预期工作< / strong>:后者无法识别为引号,PowerShell只是将字符串解释为对逐字字符串使用 its 语法,因此只需 prints 字符串。
有关更多信息,请参见this answer。