我有以下PowerShell腳本:不區分大小寫的PowerShell更換
$RegExplorer = Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters
$NullSessionPipes = "$($RegExplorer.NullSessionPipes)"
$NullSessionPipes
$NullSessionPipes = $NullSessionPipes.replace("browser", "")
$NullSessionPipes
劇本很好,只要工作的註冊表項完全相同檢查我指定的情況下匹配 - 「瀏覽器」。
但是,如果在註冊表項中說「瀏覽器」或「瀏覽器」不同,它不會進行替換。
我正在尋找一些方法使string.replace不區分大小寫。我知道我可以先使用.tolower或.toupper來轉換字符串,以便比較容易,但我不知道這個特定的註冊表項或應用程序是否區分大小寫,因此我不想更改現有密鑰的情況。
有沒有簡單的方法來做到這一點?
由於 布拉德
我想我找到了如何做到這一點 - 以下似乎工作: $ RegExplorer = GET-ItemProperty -Path HKLM:\系統\ CurrentControlSet \服務\ lanmanserver \參數 $ NullSessionPipes =「$ ($ RegExplorer.NullSessionPipes)」 $ NullSessionPipes $ NullSessionPipes = $ NullSessionPipes -ireplace( 「瀏覽器」, 「」) $ NullSessionPipes – Brad 2012-02-02 18:22:19