none
PS script that fills security zones in IE RRS feed

  • Question

  • This script fills the IE security zones. The idea is for it to be added as a logon script. I reworked it from the original script from David Wyatt on https://social.technet.microsoft.com/Forums/windowsserver/en-US/84434209-0b35-49f1-91f7-0e041ca656da/powershell-add-url-to-intranet-zone?forum=winserverpowershell

    The script was tested on PowerShell 4.0.

    Each IE security zone has an array of domains.

    It goes like this :

    #Script for adding domains to diferent zones
    
    #Define zone arrays and zone values
    $LocalArray=@("firstlocal.com", "secondlocal.com")
    $TrustedArray=@("firsttrusted.com", "secondtrusted.com")
    $RestrictedArray=@("firstrestricted.com", "secondrestricted.com")
    $LocalValue=(1)
    $TrustedValue=(2)
    $RestrictedValue=(4)
    
    #Add array elements to Local intranet zone
    ForEach ($element in $LocalArray)
    {
        #Add to Domains
        $Path=("HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\" + $element)
        if (-not (Test-Path -Path $Path))
            {
                New-Item -Path $Path
            }
        Set-ItemProperty -Path $Path -Name http -Value $LocalValue -Type DWord
        Set-ItemProperty -Path $Path -Name https -Value $LocalValue -Type DWord
    
        #Add to EscDomains
        $Path=("HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains\" + $element)
        if (-not (Test-Path -Path $Path))
            {
                New-Item -Path $Path
            }
        Set-ItemProperty -Path $Path -Name http -Value $LocalValue -Type DWord
        Set-ItemProperty -Path $Path -Name https -Value $LocalValue -Type DWord
    }
    #Add array elements to Trusted intranet zone
    ForEach ($element in $TrustedArray)
    {
        #Add to Domains
        $Path=("HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\" + $element)
        if (-not (Test-Path -Path $Path))
            {
                New-Item -Path $Path
            }
        Set-ItemProperty -Path $Path -Name http -Value $TrustedValue -Type DWord
        Set-ItemProperty -Path $Path -Name https -Value $TrustedValue -Type DWord
    
        #Add to EscDomains
        $Path=("HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains\" + $element)
        if (-not (Test-Path -Path $Path))
            {
                New-Item -Path $Path
            }
        Set-ItemProperty -Path $Path -Name http -Value $TrustedValue -Type DWord
        Set-ItemProperty -Path $Path -Name https -Value $TrustedValue -Type DWord
    }
    #Add array elements to Restricted intranet zone
    ForEach ($element in $RestrictedArray)
    {
        #Add to Domains
        $Path=("HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\" + $element)
        if (-not (Test-Path -Path $Path))
            {
                New-Item -Path $Path
            }
        Set-ItemProperty -Path $Path -Name http -Value $RestrictedValue -Type DWord
        Set-ItemProperty -Path $Path -Name https -Value $RestrictedValue -Type DWord
    
        #Add to EscDomains
        $Path=("HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains\" + $element)
        if (-not (Test-Path -Path $Path))
            {
                New-Item -Path $Path
            }
        Set-ItemProperty -Path $Path -Name http -Value $RestrictedValue -Type DWord
        Set-ItemProperty -Path $Path -Name https -Value $RestrictedValue -Type DWord
    }


    The script is ugly and long. It repeats for each of the three zones.

    Any idea how to add a second loop that would shorten it?

    Newb

    Thursday, November 6, 2014 2:31 PM

Answers

  • Your request doesn't make any sense.  You have three sets of unrelated things.  You need three loops.

    ¯\_(ツ)_/¯

    Thursday, November 6, 2014 2:46 PM

All replies