I would like to change the language in this script to Norwegian and believe I have done it successfully, however, this change has suppressed error messages that are output. The same issue is present with Using-Culture en-us
.
Any ideas on why this happens and how to fix it if possible?
My method of testing what the output error is is by creating a new VPN connection with the same name as an existing one. Without the Using-Culture function, errors are shown. With it, the errors are suppressed and the script only shows the custom message (Which is shown when an error is present regardless).
Example below shows errors as intended, but does not change the language to Norwegian:
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"
}
See full script below. This does not show errors, and I can not confirm if the language is Norwegian in the errors.
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"
}
}
I apologize for grammatical errors as English is not my first language. The top example-script is not optimized, as it is a testing script.