# Load SharePoint PowerShell PSSnapIn and the main SharePoint .net library
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#set a few variables for the script
$owner = "WebConfigModifications"
$Url = "http://sp2013:5559/"
#Get the web application we want to work with
$webapp = get-spwebapplication $Url
#$webApp.WebConfigModifications | Format-Table Name,Owner
#$webApp.WebConfigModifications.Clear()
#get the Foundation Web Application Service (the one that puts the content web apps on servers)
$farmservices = $webapp.Farm.Services | where { $_.TypeName -eq "Microsoft SharePoint Foundation Web Application" }
write-host $farmservices
$newModification = new-object Microsoft.SharePoint.Administration.SPWebConfigModification
$newModification.Path = "configuration/system.web/pages"
$newModification.Name = "enableSessionState"
$newModification.Sequence = 0
$newModification.Owner = $owner
$newModification.Type = 1 #for the enum value "SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode"
$newModification.Value = "true"
$webapp.WebConfigModifications.Add($newModification)
$newModification = new-object Microsoft.SharePoint.Administration.SPWebConfigModification
$newModification.Path = "configuration/system.webServer/modules"
$newModification.Name ="add[@name='Session']"
$newModification.Sequence = 0
$newModification.Owner = $owner
$newModification.Type =0 #for the enum value "SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode"
$newModification.Value = "<add name='Session' type='System.Web.SessionState.SessionStateModule' />"
#add our web config modification to the stack of mods that are applied
$webapp.WebConfigModifications.Add($newModification)
$webapp.Update()
#trigger the process of rebuildig the web config files on content web applications
$farmServices.ApplyWebConfigModifications()
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#set a few variables for the script
$owner = "WebConfigModifications"
$Url = "http://sp2013:5559/"
#Get the web application we want to work with
$webapp = get-spwebapplication $Url
#$webApp.WebConfigModifications | Format-Table Name,Owner
#$webApp.WebConfigModifications.Clear()
#get the Foundation Web Application Service (the one that puts the content web apps on servers)
$farmservices = $webapp.Farm.Services | where { $_.TypeName -eq "Microsoft SharePoint Foundation Web Application" }
write-host $farmservices
$newModification = new-object Microsoft.SharePoint.Administration.SPWebConfigModification
$newModification.Path = "configuration/system.web/pages"
$newModification.Name = "enableSessionState"
$newModification.Sequence = 0
$newModification.Owner = $owner
$newModification.Type = 1 #for the enum value "SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode"
$newModification.Value = "true"
$webapp.WebConfigModifications.Add($newModification)
$newModification = new-object Microsoft.SharePoint.Administration.SPWebConfigModification
$newModification.Path = "configuration/system.webServer/modules"
$newModification.Name ="add[@name='Session']"
$newModification.Sequence = 0
$newModification.Owner = $owner
$newModification.Type =0 #for the enum value "SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode"
$newModification.Value = "<add name='Session' type='System.Web.SessionState.SessionStateModule' />"
#add our web config modification to the stack of mods that are applied
$webapp.WebConfigModifications.Add($newModification)
$webapp.Update()
#trigger the process of rebuildig the web config files on content web applications
$farmServices.ApplyWebConfigModifications()
No comments:
Post a Comment