private/functions/Set-UseUnsafeHeaderParsing.ps1
function Set-UseUnsafeHeaderParsing { param( [Parameter(Mandatory,ParameterSetName='Enable')] [switch]$Enable, [Parameter(Mandatory,ParameterSetName='Disable')] [switch]$Disable ) $ShouldEnable = $PSCmdlet.ParameterSetName -eq 'Enable' $netAssembly = [Reflection.Assembly]::GetAssembly([System.Net.Configuration.SettingsSection]) if($netAssembly) { $bindingFlags = [Reflection.BindingFlags] 'Static,GetProperty,NonPublic' $settingsType = $netAssembly.GetType('System.Net.Configuration.SettingsSectionInternal') $instance = $settingsType.InvokeMember('Section', $bindingFlags, $null, $null, @()) if($instance) { $bindingFlags = 'NonPublic','Instance' $useUnsafeHeaderParsingField = $settingsType.GetField('useUnsafeHeaderParsing', $bindingFlags) if($useUnsafeHeaderParsingField) { $useUnsafeHeaderParsingField.SetValue($instance, $ShouldEnable) } } } } |