我有以下的PowerShell脚本:
$RegExplorer = Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters
$NullSessionPipes = "$($RegExplorer.NullSessionPipes)"
$NullSessionPipes
$NullSessionPipes = $NullSessionPipes.replace("browser", "")
$NullSessionPipes
只要检查的注册表键与我指定的大小写-"browser"完全匹配,脚本就能正常工作。
但是,如果注册表键的大小写不同,比如"BROWSER"或"Browser",它就无法进行替换。
我正在寻找一种使字符串替换不区分大小写的方法。我知道可以先使用 .tolower 或 .toupper 转换字符串以便更容易进行比较,但我不知道这个特定的注册表键或访问它的应用程序是否区分大小写,所以我不想改变现有键的大小写。
有没有简单的方法来解决这个问题?
$RegExplorer = Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters $NullSessionPipes = "$($RegExplorer.NullSessionPipes)" $NullSessionPipes $NullSessionPipes = $NullSessionPipes -ireplace ("BROWSER", "") $NullSessionPipes
- Brad