How to batch add URLs to trusted sites in Internet Explorer (PowerShell)

Introduction

This PowerShell script sample shows how to batch add Urls to trusted sites in Internet Explorer. 

Scenarios

Some users work on a large network with active directory. They want to add a lot of URLs to the trusted Sites Zone in Internet Explorer, and doing it manually would be time consuming, if we use this script to batch add these URLs, it would be very convenient.

Script

Step 1: Start the PowerShell Console with administrator. To run the script in the Windows PowerShell Console, type the command< Script Path>  with parameters at the Windows PowerShell Console.

Step2: If you want to know how to use the script, you can type the command Get-Help C:\Script\AddingTrustedSites.ps1 –Full to display the entire help file for this function, such as the syntax, parameters, or examples. This is shown in the following figure.

Example

Example 1: Type C:\Script\AddingTrustedSites.ps1 -TrustedSites "contoso1.com","contoso2.com" command in the Windows PowerShell Console.

This command will add 'contoso1.com' and 'contoso2.com' domain to trusted sites in Internet Explorer respectively. 

You will get a result as shown below:

Example 2: Type C:\Script\AddingTrustedSites.ps1 -PrimaryDomain "contoso.com" -SubDomain "abc.test" command in the Windows PowerShell Console.

This command will add 'abc.test.contoso.com' domain to trusted sites in Internet Explorer. 

You will get a result as shown below:

Here are some code snippets for your reference.

PowerShell
Edit|Remove
If($TrustedSites) 
{ 
    #Adding trusted sites in the registry 
    Foreach($TruestedSite in $TrustedSites) 
    { 
        #If the user does not specify the user type, by default the script will add the trusted sites for the current user. 
  
        If($HTTP) 
        { 
            CreateKeyReg -KeyPath $UserRegPath -Name $TruestedSite  
            SetRegValue -RegPath "$UserRegPath\$TruestedSite" -blnHTTP $true -DWord $DWord 
            Write-Host "Successfully added '$TruestedSite' domain to Internet Explorer trusted Sites." 
        } 
        Else 
        { 
            CreateKeyReg -KeyPath $UserRegPath -Name $TruestedSite  
            SetRegValue -RegPath "$UserRegPath\$TruestedSite" -blnHTTP $false -DWord $DWord 
            Write-Host "Successfully added '$TruestedSite' domain to Internet Explorer trusted Sites." 
        } 
    } 
}

 

Prerequisite

Windows PowerShell 2.0
Windows 7 or higher versionMicrosoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all

TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.