list - Editing a MultiString Array for a registry value in Powershell -


how create new multistring array , pass registry remotely using powershell 2.0?

#get multiline string array registry $regarry = (get-itemproperty "hklm:\system\currentcontrolset\control\lsa" -name "notification packages").("notification packages")  #create new string array [string[]]$temparry = @()  #create arraylist registry array can edit $temparrylist = new-object system.collections.arraylist(,$regarry)   # remove entry list if ( $temparrylist -contains "enpasflt" ) {        $temparrylist.remove("enpasflt") }   # add entry if ( !($temparrylist -contains "enpasfltv2x64")) {     $temparrylist.add("enpasfltv2x64") }  # convert list multi-line array  not creating new lines!!! foreach($i in $temparrylist) {$temparry += $1 = "\r\n"]}   # remove old array registry (remove-itemproperty "hklm:\system\currentcontrolset\control\lsa" -name "notification packages").("notification packages")  # add new 1 new-itemproperty "hklm:\system\currentcontrolset\control\lsa" -name "notification packages" -propertytype multistring -value "$temparry" 

everything works great except can't values go new line. i've tried /r/n , 'r'n. output in registry show on 1 line , adds literal newline , carriage return flags add. how array recognize these , not literally print them?

there's no need fiddling around arraylist , linebreaks. particularly if want modify remote registry. use microsoft.win32.registrykey class:

$server = '...'  $subkey = 'system\currentcontrolset\control\lsa' $value  = 'notification packages'  $reg = [microsoft.win32.registrykey]::openremotebasekey('localmachine', $server) $key = $reg.opensubkey($subkey, $true) $arr = $key.getvalue($value)  $arr = @($arr | ? { $_ -ne 'enpasflt' }) if ($arr -notcontains 'enpasfltv2x64') {   $arr += 'enpasfltv2x64' }  $key.setvalue($value, [string[]]$arr, 'multistring') 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -