Я хотел бы изменить язык в этом скрипте на норвежский и считаю, что сделал это успешно, однако это изменение подавило выводимые сообщения об ошибках.Та же проблема присутствует с Using-Culture en-us
.
Любые идеи о том, почему это происходит и как это исправить, если это возможно?
Мой метод тестирования заключается в создании ошибки вывода путем создания новогоVPN-соединение с тем же именем, что и существующее.Без функции Using-Culture отображаются ошибки.При этом ошибки подавляются, и сценарий отображает только пользовательское сообщение (которое отображается, когда ошибка присутствует независимо от этого).
В приведенном ниже примере ошибки показаны по назначению, но не изменяют язык наНорвежский:
try
{
$Name = Read-Host -Prompt 'Enter the profile name for this VPN connection'
$password = Read-Host -assecurestring "Please enter your Pre-shared Key"
#Default Cisco Meraki parameters
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
Add-VpnConnection -Name "$Name" -ServerAddress 193.214.153.2 -AuthenticationMethod MSChapv2 -L2tpPsk "$password" -TunnelType L2tp -RememberCredential -Force
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("VPN-profile for $Name has been created.
You may now use this connection.
Username and password are required on the first-time sign on.
Support: contact | company",0,"Completed") | Out-Null
}
catch
{
Write-Error $_.Exception.ToString()
Read-Host -Prompt "The above error occurred, please try again. If the issue persists, please contact support.
Support: contact | company
Please press Enter to exit"
}
См. Полный скрипт ниже.Это не показывает ошибки, и я не могу подтвердить, является ли язык норвежский в ошибках.
Function Using-Culture([Globalization.CultureInfo]$culture, [ScriptBlock]$script) {
$OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
trap {
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
}
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
$ExecutionContext.InvokeCommand.InvokeScript($script)
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
}
Using-Culture nb-NO {
try {
$Name = Read-Host -Prompt 'Enter the profile name for this VPN connection'
$password = Read-Host -AsSecureString "Please enter your Pre-shared Key"
# Default Cisco Meraki parameters
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
Add-VpnConnection -Name "$Name" -ServerAddress 193.214.153.2 -AuthenticationMethod MSChapv2 -L2tpPsk "$password" -TunnelType L2tp -RememberCredential -Force
# Gives popup with information on next steps
$wshell = New-Object -ComObject WScript.Shell
$wshell.Popup("VPN-profile for $Name has been created.`nYou may now use this connection.`nUsername and password is required on first time sign on.`nSupport: contact | company", 0, "Completed") | Out-Null
} catch {
# Reports error and suppresses "Completed"
Write-Error $_.Exception.ToString()
Read-Host -Prompt "The above error occurred, please try again. If the issue persists, please contact support.`support: contact | company`nPlease press Enter to exit"
}
}
Я прошу прощения за грамматические ошибки, поскольку английский не мой родной язык.Верхний пример-скрипт не оптимизирован, так как это скрипт тестирования.