My team runs CU updates on Exchange in an N-1 fashion every quarter. Everytime the updaters reset customizations to IIS and we have to change the powershell application pools to LanguageModel FullLanguage. I decided to script that for the guys so it's easier. It could be improved upon by having it connect to the various exchange servers in your environment and running it automatically. This is probably even easier to do with IISAdministration PowerShell Cmdlets | Microsoft Docs but I didn't find that until after I built my script. Hope this helps someone.
Tested in an Exchange 2016 on-prem environment.
<#
.SYNOPSIS
Fixes solarwinds AppInsight for Exchange when updates run.
.DESCRIPTION
AppInsight for Exchange requires PowerShellMode to run in FullLanguage. This will enable that. It currently
only runs on a single server, so you'll have to run it on multiple to get it to function, or call it from an ps-session.
.NOTES
#>
Set-ExecutionPolicy bypass
$ExchangeInstallPath = ‘HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup’
$webconfigpaths = @()
$webconfigpaths += Join-Path (Get-ItemProperty $ExchangeInstallPath).MsiInstallPath ClientAccess\PowerShell-Proxy\web.config #back end site path
$webconfigpaths += Join-Path (Get-ItemProperty $ExchangeInstallPath).MsiInstallPath FrontEnd\HttpProxy\PowerShell\web.config #default web site path
foreach ($webconfig in $webconfigpaths) {
$found = $null
[xml]$xml = get-content $webconfig
$settings = $xml.configuration.appSettings.add
foreach ($setting in $settings) {
if ($setting.key -eq "PSLanguageMode") {
if($setting.value -ne "FullLanguage") {
$setting.value = "FullLanguage"
$xml.Save($webconfig)
$found = $true
break
}
}
}
if ($found -ne $true) {
$newSetting = $xml.CreateElement("add")
$xml.configuration.appSettings.AppendChild($newSetting)
$newSetting.SetAttribute("key","PSLanguageMode")
$newSetting.SetAttribute("value","FullLanguage")
$xml.Save($webconfig)
}
}
Restart-WebAppPool -name MSExchangePowerShellAppPool
Restart-WebAppPool -name MSExchangePowerShellFrontEndAppPool