如何使用Powershell 2.0遠程創建新的MultiString Array並將其傳遞到註冊表?在Powershell中編輯多字符串數組以獲取註冊表值
#get the MultiLine String Array from the registry
$regArry = (Get-Itemproperty "hklm:\System\CurrentControlSet\Control\LSA" -name "Notification Packages").("Notification Packages")
#Create a new String Array
[String[]]$tempArry = @()
#Create an ArrayList from the Registry Array so I can edit it
$tempArryList = New-Object System.Collections.Arraylist(,$regArry)
# remove an entry from the list
if ($tempArryList -contains "EnPasFlt")
{
$tempArryList.Remove("EnPasFlt")
}
# Add an entry
if (!($tempArryList -contains "EnPasFltV2x64"))
{
$tempArryList.Add("EnPasFltV2x64")
}
# Convert the list back to a multi-line Array It is NOT creating new Lines!!!
foreach($i in $tempArryList) {$tempArry += $1 = "\r\n"]}
# Remove the old Array from the Registry
(Remove-ItemProperty "hklm:\System\CurrentControlSet\Control\Lsa" -name "notification packages").("Notification Packages")
# Add the new one
New-itemproperty "hklm:\System\CurrentControlSet\Control\Lsa" -name "notification packages" -PropertyType MultiString -Value "$tempArry"
一切工作很好,除了我不能得到的值去一個新的行。我試過/r/n
和'r'n
。我在註冊表中的輸出顯示了一行內的所有內容,並添加了我添加的文字換行符和回車標誌。我如何讓數組識別這些而不是直接打印它們?
在你的問題你正在使用''r'n'(單引號),但你需要使用的字符是反引號'\'',所以'\'r \'ñ '。你能確認你正在使用哪一個? – briantist 2014-12-01 22:32:26
太棒了!我會嘗試。你能給我一個加號嗎?如果你願意,你可以回答這個問題,如果它的工作,我會給你檢查。 – antman1p 2014-12-01 22:41:11