Share via


SharePoint 2010: List your SharePoint solution’s and made a web.config modification with PowerShell

It’s more than common to make an inventory of your SharePoint Solutions especially when you work in a D-Q-P environment. The inventory is essential if you want to know exactly what you have on your SharePoint environment.

Do we need a Solutions Inventory? YES! You should be sure that the solutions is installed and deployed in a Production environment should first be on a Development environment, then in Qualifying for Business testing.

Well, you sometimes have little cowboy who want to install a solution in your Production environment before going on D & Q. This script below will help you getting all the sites with the solutions installed per farm to check if the developper installed the solution in D & Q.

In this example you’ll see that Gokan.wsp has been installed and deployed on my “SharePoint-80” site so I can go to Production!

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$contentWebApp = (Get-SPFarm).services |
? {$_.typename -eq "Microsoft SharePoint Foundation Web Application"}
foreach($webApp in $contentWebApp.WebApplications)
{
    Write-Host "Web Application  : " $webApp.name
    Get-SPSolution | ForEach-Object {
        if ($_.LastOperationDetails.IndexOf($webApp.url) -gt 0)
        {
            Write-Host "    Solutions:"
            Write-Host "   " $_.DisplayName
        }
    }
}

http://gokanx.files.wordpress.com/2014/02/1.png?w=900&h=474

In case you miss and install a solution in your production even before going in Qualifying and Development you can use this script below to go withdraw some commands in the Web.config

Let’s take the example that you installed a solution named “Neoxy_activateSync”. But the developper didn’t test this on D & Q and there are some lines that should be dropped off the Web.config file because the site is doing very weir. For example, you might need to detele a SafeControl entry, register an HttpModule or customize SessionState. There is no time for a new “Mise en Production” and no time “to develop” a new solution. You can use and adapt this script to delete any configuration Modification!

$webApp = Get-SPWebApplication http://neoxy.sharepoint.com
$CookieConfigs  = $webApp.WebConfigModifications
foreach ($config in $CookieConfigs) {
                if ($config.Name.Equals("add[@name='ActivateSync']"))
                {
                                Write-Host "ConfigMod Found! Deleting ...";
                                $webApp.WebConfigModifications.Remove($config)   
                                Write-Host "ConfigMod Found! Done deleting...";
                }
                else
                {
                                Write-Host "ConfigMod not found. Name:" + $config.Name;     
                }
}
$webApp.Update()
$webApp.Parent.ApplyWebConfigModifications()

http://gokanx.files.wordpress.com/2014/02/2.png?w=900&h=396