We help IT Professionals succeed at work.

Batch o powershell to modify Internet explorer security settings

1,326 Views
Last Modified: 2017-03-31
Hi, I need help on creating either Batch file or Powershell script to modify security settings of the internet explorer.
What I need is to add multiple sites into trusted sites of the internet explorer.
I have done this through Group policy for domain computers but I also have 50 of non domain computers.

Please let me know if you have ideas.
Comment
Watch Question

Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Before the script a caveat. Internet Explorer has a list of top level domains built in. I can't find a way to access that. When IE creates the key it would make the trusted sites entry for "http://test.site.domain.tld" into:

ZoneMap
    domain.tld
        test.site: http (DWORD): 2

This presents a problem because the value of top level domain is extremely varied these days (not just .com, .net, and so on). The script "could" download the same list IE uses (https://publicsuffix.org/), but it would have to stick to the usage restrictions for that site. So... best effort, lets see how it gets on without splitting it up.

Usage:
Get-Content YourListOfSites.txt |C:\Somewhere\Add-ZoneMapItem.ps1 -Zone TrustedSites

Open in new window

The script, to fit usage, save as Add-ZoneMapItem.ps1
param(
    # The URL to add.
    [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
    [Uri]$Url,

    # Add the entry to the specified zone
    [Parameter(Mandatory = $true)]
    [ValidateSet('MyComputer', 'LocalIntranet', 'TrustedSites', 'Internet', 'RestrictedSites')]
    [String]$Zone,

    # By default, create entries for all users.
    [Switch]$CurrentUser
)

begin {
    [Int32]$zoneNumber = switch ($Zone) {
        'MyComputer'      { 0 }
        'LocalIntranet'   { 1 }
        'TrustedSites'    { 2 }
        'Internet'        { 3 }
        'RestrictedSites' { 4 }
    }
    $regKey = '{0}:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap' -f ('HKLM', 'HKCU')[$CurrentUser.ToBool()]
}

process {
    $domainKey = Join-Path $regKey $Url.Host
    if (-not (Test-Path $domainKey)) {
        $null = New-Item $domainKey -ItemType Key
    }

    if ($Url.Scheme) {
        $valueName = $Url.Scheme
    } else {
        $valueName = '*'
    }

    Set-ItemProperty $domainKey -Name $valueName -Value $zoneNumber -Force
}

Open in new window

Tech ManInformation Technology

Author

Commented:
Thank you Chris,
I will test this but before I have couple of questions:
- How should I structure my .txt file? Should I separate website addresses with space, comma or new line?
- Can I have my source file (.txt) located somewhere in internet. For example if I have my text file in OneDrive, that way I dont have to copy the file to each machine?

I would greatly appreciate your opinion.

Thank you
PowerShell Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Tech ManInformation Technology

Author

Commented:
Chris, I run the Script locally but unfortunately it does not add sites to the trusted sites list. How can I troubleshot this?

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions