Powershell Scripting games - Day 5

Registry keys. Sorry for the silly humor - don’t know how and why Tonto got in there.

Thanks to Rob Rohr - for helping me out here.

# first we define some variables
$ourpath = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings"
$Maxdl1_0 = "MaxConnectionsPer1_0Server"
$Maxdl = "MaxConnectionsPerServer"
#for IE8
$ie8path = "HKLM:\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_MAXCONNECTIONSPERSERVER"
$ie8path1_0 = "HKLM:\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_MAXCONNECTIONSPER1_0SERVER"
$ie8Max = "iexplore.exe"
function upsertReg($path, [string]$name, [int]$value, [string]$propType) {
    "Path: $path"
    "Name: $name"
    "Target Value:  $value"
    # verify path exists
    $keyExists = Test-Path $path

    if ($keyExists -eq $true) {

        # check if named registry item exists at path
        $reg = get-itemproperty $path
        if ($reg.$($name) -eq $null) {
            # value doesn't exist... Create.
            Write-Host " Key is not there Kimosabi. Let's make some magic."
            New-ItemProperty $path -name $name -value $value -propertytype ` 
        else {
            # value exists... Update...
            $curr = Get-ItemProperty -path $path -name $name
            Write-Host "Hold you horses Kimosabi. It is already there!"
            $confirm = read-host " You have ($curr) as your current value and ` 
                we are going to change it to ==>$value. Are you sure? (Y/N)"
            if ($confirm -eq "Y") {
                Set-ItemProperty -path $path -name $name -value $value
                Write-Host "Entry has been changed Kimosabi."
            else {
                Write-Host "You chose not to change it - so it stays there."
    } else {
      "Path doesn't exist.  Registry entry not created."

 # create/update registry items using the function
 upsertReg $ourpath $Maxdl 10 DWord
 upsertReg $ourpath $Maxdl1_0 10 DWord
 upsertReg $ie8path $ie8Max 10 DWord
 upsertReg $ie8path1_0 $ie8Max 10 DWord