不确定此脚本有什么问题
$SSODelete= "Delete"
$SSOfiles = "SSo.xml"
$channlename = "INC8-Patch"
write-host $channlename
if ($channelname -like *INC8*){
$SSOarg = "$SSODelete $SSOfiles"
Write-Host $SSOarg
}
它抛出以下错误:
You must provide a value expression following the '*' operator. At line:5 char:25 + if ($channelname -like *INC8*){ + ~~~~~ Unexpected token 'INC8*' in expression or statement.
尝试使用"*INC8*"
和'*INC8'
,但它不符合if
声明。
为脚本添加屏幕截图及其结果 Simple Script and results
答案 0 :(得分:1)
PowerShell -like
运算符应与引用的匹配字符串一起使用,例如$variable -like "*pattern*"
。 -like
仅接受简单通配符(*
);您可以使用-match
与正则表达式(regexps)进行比较。请参阅Get-Help about_Comparison_Operators
。
答案 1 :(得分:0)
谢谢,这是由于变量名称我正在比较......我需要更加谨慎