gpt4 book ai didi

Powershell 比较 if 结构中的字符串给出错误结果

转载 作者:行者123 更新时间:2023-12-01 14:35:32 25 4
gpt4 key购买 nike

简单的 Powershell 脚本:

$key = Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager"
$bootexecute = $key.BootExecute

write-host $bootexecute

if ($bootexecute -eq "autocheck autochk *") {
return $false
} else {
return $true
}

这是我得到的输出:

autocheck autochk /r \??\C: autocheck autochk *
False

因此,即使 $bootexecute 变量不完全等于“autocheck autochk *”,我仍然得到“False”结果,而它应该在此处返回“True”。

发生了什么事,我在这里错过了什么?

编辑,澄清一下:我确实想检查字符串“autocheck autochk *”。包括星号。

最佳答案

由于 $bootexecute 的计算结果为:

autocheck autochk /r \??\C: autocheck autochk *

-eq 可能不是您想要的。

相反,请使用正则表达式和-match:

if ($bootexecute -match "autocheck autochk .*") {
return $false
} else {
return $true
}

可以简化为:

$bootexecute -match "autocheck autochk .*"
return

关于Powershell 比较 if 结构中的字符串给出错误结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38101368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com