Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Put this in a file called AddWebConfigMods.ps1</p> <pre><code>Param ($weburl, $WebConfigModifications ) $url = New-Object System.Uri($webUrl) [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null $webApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($url) #delete mods by the owners being added $ownerstodelete = $WebConfigModifications | Group-Object owner | Select-Object Name foreach($owner in $ownerstodelete) { $modstodelete = @() foreach($mod in $webApp.WebConfigModifications) { if($mod.Owner -eq $owner.Name) { $modstodelete += $mod } } Write-Host ("Deleting " + $modstodelete.Count + " mods for owner: " + $owner) foreach($delmod in $modstodelete) { Write-Host (" + Deleting " + $delmod.Value) $webApp.WebConfigModifications.Remove($delmod) | Out-Null } } #this is where we start to add mods $i = 0; Write-Host ("Adding " + $WebConfigModifications.Count + " webconfig modifications to " + $weburl) foreach($modEntry in $WebConfigModifications) { Write-Host (" + Adding " + $modEntry.Value) $mod = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification $mod.Path = $modEntry.Path $mod.Name = $modEntry.Name $mod.Sequence = $i++ $mod.Owner = $modEntry.Owner $mod.Type = $modEntry.Type $mod.Value = $modEntry.Value $webApp.WebConfigModifications.Add($mod) } $webApp.Update() $webApp.WebService.ApplyWebConfigModifications() </code></pre> <p>Then create a csv file with your configs like so</p> <pre><code>Name,Path,Owner,Type,Value system.serviceModel,configuration,alinean-common,EnsureSection,&lt;system.serviceModel/&gt; connectionStrings,configuration,alinean-common,EnsureSection,&lt;connectionStrings /&gt; appSettings,configuration,alinean-common,EnsureSection,&lt;appSettings /&gt; serviceHostingEnvironment,configuration/system.serviceModel,alinean-common,EnsureChildNode,&lt;serviceHostingEnvironment aspNetCompatibilityEnabled='true'/&gt; </code></pre> <p>Then in another ps1 script, ideally the one you use to deploy your solution, import the csv config options and call the function created in the first code block:</p> <pre><code>#read config mods from CSVs $mods = Import-CSV .\config\admin-common.webconfigmods.csv Write-Host "Applying configuration modifications" #add web config mods to sharepoint using powershell script &amp;.\AddWebConfigMods "[sharepoint site url]" $mods &amp;stsadm -o execadmsvcjobs </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload