Created
December 7, 2018 02:13
-
-
Save shirhatti/f68b0f13639150b813b7c9e25c16654e to your computer and use it in GitHub Desktop.
Powershell script to work around shared config block in ANCM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module IISAdministration | |
# Stop WAS/W3SVC | |
Stop-Service -Name WAS -Force | |
# Disable shared config | |
$sm = Get-IISServerManager | |
$sm.GetRedirectionConfiguration().GetSection("configurationRedirection").Attributes["enabled"].Value = $false | |
$sm.CommitChanges() | |
# Initialize variables | |
$aspNetCoreModuleFilePath="$env:windir\system32\inetsrv\aspnetcore.dll" | |
$aspNetCoreModuleV2FilePath="$env:ProgramFiles\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll" | |
$sm = Get-IISServerManager | |
# Set Allow for handlers section | |
$appHostconfig = $sm.GetApplicationHostConfiguration() | |
$section = $appHostconfig.GetSection("system.webServer/handlers") | |
$section.OverrideMode="Allow" | |
# Add aspNetCore section to system.webServer | |
$sectionaspNetCore = $appHostConfig.RootSectionGroup.SectionGroups["system.webServer"].Sections.Add("aspNetCore") | |
$sectionaspNetCore.OverrideModeDefault = "Allow" | |
$sm.CommitChanges() | |
# Configure globalModule | |
$globalModules = Get-IISConfigSection "system.webServer/globalModules" | Get-IISConfigCollection | |
New-IISConfigCollectionElement $globalModules -ConfigAttribute @{"name"="AspNetCoreModule";"image"=$aspNetCoreHandlerFilePath} | |
New-IISConfigCollectionElement $globalModules -ConfigAttribute @{"name"="AspNetCoreModuleV2";"image"=$aspNetCoreModuleV2FilePath} | |
# Configure module | |
$modules = Get-IISConfigSection "system.webServer/modules" | Get-IISConfigCollection | |
New-IISConfigCollectionElement $modules -ConfigAttribute @{"name"="AspNetCoreModule"} | |
New-IISConfigCollectionElement $modules -ConfigAttribute @{"name"="AspNetCoreModuleV2"} | |
# Enable shared config | |
$sm = Get-IISServerManager | |
$sm.GetRedirectionConfiguration().GetSection("configurationRedirection").Attributes["enabled"].Value = $true | |
$sm.CommitChanges() | |
# Start WAS/W3SVC | |
Start-Service -Name W3SVC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment