SharePoint - Automating web.config Changes for Proxy Server Settings


One of my customers recently needed to provide the ability for end users to access external RSS feeds from SharePoint, this requires that all SharePoint Web Servers have access to the Internet. In this specific case my customer controlled access to the Internet via a proxy server therefore the easiest way to set this up was make some modifications to the web.config for the Web Applications that needed the ability to connect to external RSS feeds as per - https://msdn.microsoft.com/en-us/library/kd3cf2ex(v=vs.85).aspx.

Rather than making nasty manual changes to the web.config files on each Web server we decided to apply the changes correctly using the Microsoft.SharePoint.Administration.SPWebConfigModification class, which takes care of rolling out these changes to all Web Servers. I put together the PowerShell below to automate the addition of these settings rather than deploying via a solution (which seemed a little overkill).

One thing worth pointing out is that the account that the Application Pool for the Web Application that you configure to use a Proxy will require permissions to use the Proxy.

Simply update the highlighted values and execute, this was tested on SharePoint 2010 but should also work with SharePoint 2013 (and possibly MOSS 2007!):

Add Proxy Settings

asnp *SharePoint* -ea 0
#Bind to Web App
$WebApp = Get-SPWebApplication http://intranet.contoso.com
#Configure Auth Setting
$ProxyCreds = New-Object -TypeName "Microsoft.SharePoint.Administration.SPWebConfigModification" -ArgumentList "useDefaultCredentials", "configuration/system.net/defaultProxy"
$ProxyCreds.Sequence = 0
$ProxyCreds.Owner = "Proxy for RSS Feeds"
$ProxyCreds.Type = "1"
$ProxyCreds.Value = "True"
$WebApp.WebConfigModifications.Add($ProxyCreds)
#Add Proxy Section and Required Settings
$Proxy = New-Object -TypeName "Microsoft.SharePoint.Administration.SPWebConfigModification" -ArgumentList "proxy", "configuration/system.net/defaultProxy"
$Proxy.Sequence = 0
$Proxy.Owner = "Proxy for RSS Feeds"
$Proxy.Type = "0"
$Proxy.Value = "<proxy usesystemdefault='false' proxyaddress='http://proxy:8080' bypassonlocal='true'></proxy>"
$WebApp.WebConfigModifications.Add($Proxy)
$WebApp.Update()
$WebApp.Parent.ApplyWebConfigModifications()


Remove Proxy Settings

$ProxySettings = $Webapp.WebConfigModifications | Where {$_.Owner -eq "Proxy for RSS Feeds"}
Foreach ($ProxySetting in $ProxySettings)
{
$WebApp.WebConfigModifications.Remove($ProxySetting)
$WebApp.Update()
$WebApp.Parent.ApplyWebConfigModifications()
}

Brendan Griffin - @brendankarl


Comments (2)

  1. SharePoint 2013 Online Training says:

    Wonderful post however I was wondering if you could write a little more on this topic? I’d be very thankful if you could elaborate a little bit further. Thank you!
    http://staygreenacademy.com/

  2. Dr Sylvester Benson says:

    GET YOUR PROBLEM SOLVE TODAY WITH MY PROFESSION IN ANY SPIRITUAL SPELL OR ANY KIND OF PHYSICAL BATTLE THAT NEED, MY NAME IS DR SYLVESTER AND THIS IS MY EMAIL FOR CONTACT (stbenson391@gmail.com) OR YOU CAN FOLLOW HIM UP ON FACEBOOK BY MY NAME (SYLVESTER E BENSON)
    ON FACEBOOK OR CALL ME ON MY MOBILE NUMBER +2348136090988, AM ALWAYS AVAILABLE TO RENDER YOU HELP WITH EXPERIENCE OF 32 YEARS IN SPELL CASTING AND HERBAL MEDICURE TO CURE ANY KIND OF DISEASE THAT YOU MAY HAVE, CONTACT ME ON ANY KIND OF ISSUES.

Skip to main content