Kaseya Community

Editing Multi Value registry keys.

  • Hey everyone,

    I'm trying to script the changes for this issue that we've noticed on a few of our sites lately;

    http://blogs.technet.com/sbs/archive/2008/07/17/some-services-may-fail-to-start-or-may-not-work-properly-after-installing-ms08-037-951746-and-951748.aspx

    I need to change the reserved ports registry entry, which is multi valued.

    How can this be done in a Kaseya script?

    Legacy Forum Name: Editing Multi Value registry keys.,
    Legacy Posted By Username: LANWorx
  • This is something I've been meaning to script so this is what I came up with. You will need to have PowerShell v.1.0 installed for this script to work. However, you can script the installation of PowerShell also. Smile

    I didn't find anything else that reliably worked with REG_MULTI_SZ very well and since I already have PowerShell installed on everything...

    Here's the KScript:
    Script Name: Update ReservedPorts Registry Value
    Script Description: This script updates the HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\ReservedPorts registry value based on this article:
    http://blogs.technet.com/sbs/archive/2008/07/17/some-services-may-fail-to-start-or-may-not-work-properly-after-installing-ms08-037-951746-and-951748.aspx

    IF Check Registry Value
    Parameter 1 : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\Install
    Exists :1
    THEN
    Write File
    Parameter 1 : #vAgentConfiguration.agentTempDir#\Update-ReservedPorts.ps1
    Parameter 2 : VSASharedFiles\General Scripts\Update-ReservedPorts.ps1
    OS Type : 0
    Execute File
    Parameter 1 : %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
    Parameter 2 : -noprofile Set-ExecutionPolicy RemoteSigned
    Parameter 3 : 3
    OS Type : 0
    Execute File
    Parameter 1 : %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
    Parameter 2 : -noprofile . #vAgentConfiguration.agentTempDir#\Update-ReservedPorts.ps1
    Parameter 3 : 1
    OS Type : 0
    Delete File
    Parameter 1 : #vAgentConfiguration.agentTempDir#\Update-ReservedPorts.ps1
    OS Type : 0
    ELSE
    Write Script Log Entry
    Parameter 1 : PowerShell is not installed.
    OS Type : 0



    This is just a quick & dirty KScript. I didn't have it write to the script log if it was successful. You could also have it grab the old and new values and write to the KServer as a double-check and a CYA.

    Here's the Update-ReservedPorts.ps1 script file:

    $NP="1645-1646","1701-1701","1812-1813","2883-2883","4500-4500";$P="
    HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters";$RP=(Get-ItemProperty -Path $P -Name "ReservedPorts").ReservedPorts;$RP=$RP+=$NP;Set-ItemProperty -Path $P -Name "ReservedPorts" -Value $RP


    Watch out for the forum software adding extra spaces!

    Michael

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: RCS-Michael
  • Hey Michael,

    You're a legend for posting this. Just quickly, how do I use this?

    Do I simply save the second script as a ps1 file in say, notepad?

    I've never actually used PowerShell before (I know! Im a disgrace!)

    Cheers,

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: LANWorx
  • Yes, just save it using Notepad and correct any added spaces or line-wrapping that was done by the forum software (the script is a one-liner).

    Michael

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: RCS-Michael
  • Ah! If you hadn't pointed out that it's a one liner, I doubt I would have picked that up.

    Thanks Michael!

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: LANWorx
  • Here's one that doesn't require power shell. You'll need to export and upload a .reg file to your k server first.

    Script Name: Create server port reservations
    Script Description:

    IF True
    THEN
    Get Variable
    Parameter 1 : 10
    Parameter 2 :
    Parameter 3 : AgentTemp
    OS Type : 0
    Execute Shell Command
    Parameter 1 : reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v ReservedPorts >> #AgentTemp#\ReservedPorts.txt
    Parameter 2 : 0
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #AgentTemp#\ReservedPorts.txt
    Parameter 3 : ReservedPorts
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : Previous Reserved Ports before update #ReservedPorts#
    OS Type : 0
    Write File
    Parameter 1 : #AgentTemp#\ReservedPorts.reg
    Parameter 2 : VSASharedFiles\Reserved Ports.reg
    OS Type : 0
    Execute Shell Command
    Parameter 1 : reg import #AgentTemp#\ReservedPorts.reg
    Parameter 2 : 0
    OS Type : 0
    Execute Shell Command
    Parameter 1 : reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v ReservedPorts >> #AgentTemp#\ReservedPorts.txt
    Parameter 2 : 0
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #AgentTemp#\ReservedPorts.txt
    Parameter 3 : ReservedPorts
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : New Reserved Ports after update #ReservedPorts#
    OS Type : 0
    Delete File
    Parameter 1 : #AgentTemp#\ReservedPorts.reg
    OS Type : 0
    ELSE



    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: rwitt
  • My .reg file

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]
    "ReservedPorts"=hex(7):31,00,34,00,33,00,33,00,2d,00,31,00,34,00,33,00,34,00,\
    00,00,31,00,38,00,30,00,31,00,2d,00,31,00,38,00,30,00,31,00,00,00,33,00,33,\
    00,34,00,33,00,2d,00,33,00,33,00,34,00,33,00,00,00,31,00,34,00,33,00,33,00,\
    2d,00,31,00,34,00,33,00,34,00,00,00,31,00,37,00,34,00,35,00,2d,00,31,00,37,\
    00,34,00,35,00,00,00,31,00,30,00,38,00,30,00,2d,00,31,00,30,00,38,00,30,00,\
    00,00,31,00,37,00,31,00,38,00,2d,00,31,00,37,00,32,00,30,00,00,00,31,00,36,\
    00,34,00,35,00,2d,00,31,00,36,00,34,00,36,00,00,00,31,00,37,00,30,00,31,00,\
    2d,00,31,00,37,00,30,00,31,00,00,00,31,00,38,00,31,00,32,00,2d,00,31,00,38,\
    00,31,00,33,00,00,00,32,00,38,00,38,00,33,00,2d,00,32,00,38,00,38,00,33,00,\
    00,00,34,00,35,00,30,00,30,00,2d,00,34,00,35,00,30,00,30,00,00,00,31,00,38,\
    00,30,00,31,00,2d,00,31,00,38,00,30,00,31,00,00,00,34,00,30,00,37,00,30,00,\
    2d,00,34,00,30,00,37,00,31,00,00,00,33,00,35,00,30,00,30,00,2d,00,33,00,36,\
    00,31,00,39,00,00,00,00,00


    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: rwitt