Skip to main content

Modify the Internet Explorer Compatibility List with PowerShell

Here is a good, real world question.  While examining the Group Policies settings for Internet Explorer in class.  The question came about as to whether or not the list can be modified in Group Policy by using PowerShell.  Well, yes you can.

The first thing is to determine what registry key we need to modify.  For the Compatibility list, the key is:
“HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Internet Explorer\BrowserEmulation\PolicyList”

To utilize PowerShell for this task, we first need to add the Group Policy Module.
Import-Module GroupPolicy

Next, to add the website names www.abc.com to the GPO named IE Settings, type:
Set-GPRegistryValue –Name “IE Settings” –Key “HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Internet Explorer\BrowserEmulation\PolicyList” –ValueName “www.abc.com” –Type String –Value “www.abc.com”

Opening the GPO in the Group Policy Management Editor and manually entering the web site would be faster for a single site.  But what if you have a whole list?  That is where we need to turn to a PowerShell script.

The PowerShell code below will allow you to populate the contents of a text file in the Internet Explorer 7 Compatibility list in the GPO of your choice.  This will remove any entries already in the GPO.  Each time it is ran, it purges the compatibility list and recreates it.  For that reason, use the text file as your master list for websites that need to be ran in compatibility mode.

To use this code, copy and paste it into your PowerShell ISE.  Change the file location for the text file and the name of the GPO and run it.

<#===========================================================
Script Name: ManageCompatabilityList.ps1
Version: 1.0
Author: Jason A. Yoder, MCT

Website: www.MCTExpert.com
Blog: www.MCTExpert.BlogSpot.com


Script Purpose:
This script will add websites to the Internet Explorer 7
Compatibility List in a Group Policy.  The website address
will come from a text file.  The text file will completely
manage what is contained in the Compatibility list GPO. If
a website is removed from the text file, or is not in the
it will also be removed from the GPO.

Requirements:
This script has only been tested on a Windows Server 2008 R2
domain controller.



Revision History:
1.0
Created: January 28, 2011
Status: Completed
===========================================================#>



# ===========================================================
# Global Variables



$Website_List = "E:\Compatibility List\Websites.txt"
# file and location of the text file holding the list of
# websites that need to be included in the Compatibility
# list of the GPO.



$GPOName = "IE Settings"
# This is the name of the Group Policy that contains the
# Compatibility List to be modified.



$ListKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Internet Explorer\BrowserEmulation\PolicyList"
# The registry key to be modified. 


# == End of Global Variables ================================


# ===========================================================
# Main Code:



Import-Module GroupPolicy
# Imports the GroupPolicy cmdlets for PowerShell into this
# session.



$ErrorActionPreference = "SilentlyContinue"
# Should the Compatibility list inside the GPO be not
# configured, an error would be generated.  This allows
# the script to continue execution.



# Remove the current contents of the Compatibility List.
Get-GPRegistryValue -Name $GPOName -Key $ListKey | `
Remove-GPRegistryValue -Name $GPOName -Key $ListKey

# Load the list of websites into memory.
$Websites = Get-Content $Website_List


# Add each of the websites to the GPO
For ($i = 0; $i -le $Websites.count-1; $i++)
    {
    Set-GPRegistryValue -Name $GPOName `
    -Key $ListKey -ValueName $Websites[$i] `
    -Type String -Value $Websites[$i]
    }
   
   
$ErrorActionPreference = "Stop"
#Reset the error action mode of PowerShell.


# == End of Main Code =======================================

Comments

Popular posts from this blog

Adding a Comment to a GPO with PowerShell

As I'm writing this article, I'm also writing a customization for a PowerShell course I'm teaching next week in Phoenix.  This customization deals with Group Policy and PowerShell.  For those of you who attend my classes may already know this, but I sit their and try to ask the questions to myself that others may ask as I present the material.  I finished up my customization a few hours ago and then I realized that I did not add in how to put a comment on a GPO.  This is a feature that many Group Policy Administrators may not be aware of. This past summer I attended a presentation at TechEd on Group Policy.  One organization in the crowd had over 5,000 Group Policies.  In an environment like that, the comment section can be priceless.  I always like to write in the comment section why I created the policy so I know its purpose next week after I've completed 50 other tasks and can't remember what I did 5 minutes ago. In the Group Policy module for PowerShell V3, th

Return duplicate values from a collection with PowerShell

If you have a collection of objects and you want to remove any duplicate items, it is fairly simple. # Create a collection with duplicate values $Set1 = 1 , 1 , 2 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2   # Remove the duplicate values. $Set1 | Select-Object -Unique 1 2 3 4 5 6 7 What if you want only the duplicate values and nothing else? # Create a collection with duplicate values $Set1 = 1 , 1 , 2 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2   #Create a second collection with duplicate values removed. $Set2 = $Set1 | Select-Object -Unique   # Return only the duplicate values. ( Compare-Object -ReferenceObject $Set2 -DifferenceObject $Set1 ) . InputObject | Select-Object – Unique 1 2 This works with objects as well as numbers.  The first command creates a collection with 2 duplicates of both 1 and 2.   The second command creates another collection with the duplicates filtered out.  The Compare-Object cmdlet will first find items that are diffe

How to list all the AD LDS instances on a server

AD LDS allows you to provide directory services to applications that are free of the confines of Active Directory.  To list all the AD LDS instances on a server, follow this procedure: Log into the server in question Open a command prompt. Type dsdbutil and press Enter Type List Instances and press Enter . You will receive a list of the instance name, both the LDAP and SSL port numbers, the location of the database, and its status.