Вы можете создать функцию прокси, изменить тип параметра Encoding на System.String и манипулировать им в блоке Begin.Я включил этот пример в модуль PowerShell Proxy Extensions .
function Send-MailMessage
{
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$true)]
[Alias('PsPath')]
[ValidateNotNullOrEmpty()]
[System.String[]]
${Attachments},
[ValidateNotNullOrEmpty()]
[System.String[]]
${Bcc},
[Parameter(Position=2)]
[ValidateNotNullOrEmpty()]
[System.String]
${Body},
[Alias('BAH')]
[Switch]
${BodyAsHtml},
[Parameter()]
[ValidateSet('ASCII','UTF8','UTF7','UTF32','Unicode','BigEndianUnicode','Default','OEM')]
[ValidateNotNullOrEmpty()]
[Alias('BE')]
[System.String]
$Encoding,
[ValidateNotNullOrEmpty()]
[System.String[]]
${Cc},
[Alias('DNO')]
[ValidateNotNullOrEmpty()]
[System.Net.Mail.DeliveryNotificationOptions]
${DeliveryNotificationOption},
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[System.String]
${From},
[Parameter(Position=3)]
[Alias('ComputerName')]
[ValidateNotNullOrEmpty()]
[System.String]
${SmtpServer},
[ValidateNotNullOrEmpty()]
[System.Net.Mail.MailPriority]
${Priority},
[Parameter(Mandatory=$true, Position=1)]
[Alias('sub')]
[ValidateNotNullOrEmpty()]
[System.String]
${Subject},
[Parameter(Mandatory=$true, Position=0)]
[ValidateNotNullOrEmpty()]
[System.String[]]
${To},
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
${Credential},
[Switch]
${UseSsl}
)
begin
{
try
{
$outBuffer = $null
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
{
$PSBoundParameters['OutBuffer'] = 1
}
if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Encoding'))
{
$null = $PSCmdlet.MyInvocation.BoundParameters.Remove('Encoding')
$newValue = & {
if ($Encoding -eq 'OEM')
{
[System.Text.Encoding]::GetEncoding($Host.CurrentCulture.TextInfo.OEMCodePage)
}
else
{
[System.Text.Encoding]::$Encoding
}
}
$null = $PSCmdlet.MyInvocation.BoundParameters.Add('Encoding',$newValue)
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Send-MailMessage', [System.Management.Automation.CommandTypes]::Cmdlet)
$scriptCmd = {& $wrappedCmd @PSBoundParameters }
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
}
catch
{
throw
}
}
process
{
try
{
$steppablePipeline.Process($_)
}
catch
{
throw
}
}
end
{
try
{
$steppablePipeline.End()
}
catch
{
throw
}
}
}