Applications Systems
Update PSLanguageMode PowerShell settings for target AppInsight for Exchange nodes in SAM
Starting in SAM 2020.2.6, a minimum of RestrictedLanguage is required for the PSLanguageMode setting on target servers. This article includes a PowerShell script that you can run on Exchange servers to adjust that setting.
First published date
Last published date
Overview
Note: SolarWinds recommends using PowerShell 5.1 or later on target servers.
Use the following PowerShell script to reconfigure the IIS endpoint of existing Exchange machines to change the PSLanguageMode Setting to RestrictedLanguage.
-- Scripts are not supported under any SolarWinds support program or service.
-- Scripts are provided AS IS without warranty of any kind. SolarWinds further
-- disclaims all warranties including, without limitation, any implied warranties
-- of merchantability or of fitness for a particular purpose. The risk arising
-- out of the use or performance of the scripts and documentation stays with you.
-- In no event shall SolarWinds or anyone else involved in the creation,
-- production, or delivery of the scripts be liable for any damages whatsoever
-- (including, without limitation, damages for loss of business profits, business
-- interruption, loss of business information, or other pecuniary loss) arising
-- out of the use of or inability to use the scripts or documentation.
$CantSetupLanguageMode = 16026
$ExitCodeOk = 0
### Functions declaration ###
function ExitWithCode {
Param($ExitCode)
$host.SetShouldExit($ExitCode)
exit
}
function Configure-PSLanguageMode {
Param($webSitePath)
try {
Write-Output "Current value of PSLanguageMode setting on PowerShell site: "
$psLanguageMode = Get-WebConfiguration appSettings/* $webSitePath | select key,value | where {$_.key -eq 'PSLanguageMode'}
Write-Output $psLanguageMode | Out-String
if ($psLanguageMode -eq $null) {
Write-Output "PSLanguageMode key is missing inside web.config\appSettings section. Will create one..."
Add-WebConfigurationProperty -pspath $webSitePath -filter "appSettings" -name "." -value (@{key='PSLanguageMode'; value='RestrictedLanguage'})
} elseif ($psLanguageMode.value -eq "FullLanguage") {
Write-Output "Switch PSLanguageMode setting to RestrictedLanguage for PowerShell site"
Set-WebConfiguration -filter '/appSettings/*[@key="PSLanguageMode"]' -PSPath $webSitePath -value (@{value="RestrictedLanguage"})
}
Write-Output "To apply PSLanguageMode setting we have to recycle application pool: "
# Get pool name by the site name:
$pool = (Get-Item $webSitePath | Select-Object applicationPool).applicationPool
Write-Output $pool
# Recycle the application pool:
Restart-WebAppPool $pool
Start-Sleep -s 15
Write-Output "Check PSLanguageMode setting: "
$psLanguageMode = Get-WebConfiguration appSettings/* $webSitePath | select key,value | where {$_.key -eq 'PSLanguageMode'}
Write-Output $psLanguageMode | Out-String
} catch {
Write-Output "Unable to setup PSLanguageMode setting for PowerShell web site. ERROR: $($Error[0])"
ExitWithCode $CantSetupLanguageMode
}
}
$webSitePath = "IIS:\sites\Default Web Site\PowerShell"
Write-Output "Configuring PSLanguageMode setting for web site: "
Write-Output $webSitePath
Configure-PSLanguageMode $webSitePath
$hasExchangeBackEndWebSite = Get-WebSite | where {$_.name -eq 'Exchange Back End'}
if ($hasExchangeBackEndWebSite -ne $null) {
Write-Output "Detected second PowerShell web site instance under 'Exchange Back End' web site, probably system is running Exchange 2013. Will configure second instance as well.."
Write-Output "##############"
$webSitePath = "IIS:\sites\Exchange Back End\PowerShell"
Write-Output "Configuring PSLanguageMode setting for web site: "
Write-Output $webSitePath
Configure-PSLanguageMode $webSitePath
}