Many of you have asked for a script we use in the TechNet ISA Server 2004 Technical Overview (TNT1–111) webcast.  The blockwebsites.vbs script creates a ISA firewall access rule and builds a list of websites that will be blocked.

This script is obviously useful for a number of reasons.  First, it could be used quite immediately to block websites you deem inappropriate to your companies day to day business.  Second, it is a good example of how to use a script and create a rule inside ISA Server 2004.

The following set of code is very similar to the script we run in the demos you saw during my webcast.  This sample is taken directly from the ISA Server 2004 CD so I would recommend reviewing the other samples that are there.  Enjoy!!!

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright (c) Microsoft Corporation. All rights reserved.
' THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE
' RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE
' USER. USE AND REDISTRIBUTION OF THIS CODE, WITH OR WITHOUT MODIFICATION, IS
' HEREBY PERMITTED.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This script creates a new URL set in the URLSets collection of the firewall,
' adds sites to the URL set, creates a new access rule, and adds the new URL set
' to the objects referenced in the URLSets property of the access rule.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub AddRuleAndUrlSet()

    ' Define enumeration values.
    const fpcInclude = 0
    const fpcSpecifiedProtocols = 1

    ' Create the root obect.
    Dim root  ' The FPCLib.FPC root object
    Set root = CreateObject("FPC.Root")

    'Declare the other objects needed.
    Dim firewall    ' An FPCArray object
    Dim policyrules ' An FPCPolicyRules collection
    Dim urlsets     ' An FPCURLSets colection
    Dim urlset      ' An FPCURLSet object
    Dim newrule     ' An FPCPolicyRule object

    ' Get references to the array object (firewall), the policy rules collection,
    ' and the URL sets collection.
    Set firewall = root.GetContainingArray
    Set policyrules = firewall.ArrayPolicy.PolicyRules
    Set urlsets = firewall.RuleElements.URLSets


    WScript.Echo "Creating a new URL set containing sites to be blocked ..."

    Set urlset = urlsets.Add("Blocked Web Sites")
    urlset.Add "
http://www.northwindtraders.com"
    urlset.Add "
http://www.widgets.com"
    urlset.Save

    WScript.Echo "Creating a new access rule ..."
    Set newrule = policyrules.AddAccessRule("Deny Access to Some Web Sites")

    ' Define the source for the new access rule.
    newrule.SourceSelectionIPs.Networks.Add "External", fpcInclude

    ' Add the new destination URL set to the objects referenced by the URLSets property
    ' of the new access rule.
    newrule.AccessProperties.URLSets.Add "Blocked Web Sites", fpcInclude

    'Set the protocols to HTTP and HTTPS.
    newrule.AccessProperties.SpecifiedProtocols.Add "HTTP", fpcInclude
    newrule.AccessProperties.SpecifiedProtocols.Add "HTTPS", fpcInclude 
    newrule.AccessProperties.ProtocolSelectionMethod =  fpcSpecifiedProtocols

    ' Set the user set to which the rule applies.
    newrule.AccessProperties.UserSets.Add "All Users", fpcInclude

    'Save the changes to the new access rule.
    policyrules.Save
    WScript.Echo "Done!"

End Sub

AddRuleAndUrlSet