locked
Changing PS language supresses errors RRS feed

  • Question

  • Hi all.

    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 is 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 a existing one. Without the Using-Culture function, errors are shown. With it, the errors are supressed and the script only shows the custom message (Which is shown when a error is present regardless).

    >The script adds a VPN connection based on Cisco Meraki default connections.

    Below is a example that produces errors as normal:

    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 supresses "Completed"
            Write-Error $_.Exception.ToString()
            Read-Host -Prompt "The above error occurred, please try again. If the issue persists, please contact support.`nSupport: contact | company`nPlease press Enter to exit"
        }

    See below for the full script, in which the language change is implemented (I belive). 

    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 supresses "Completed"
            Write-Error $_.Exception.ToString()
            Read-Host -Prompt "The above error occurred, please try again. If the issue persists, please contact support.`nSupport: contact | company`nPlease press Enter to exit"
        }
    }

    I have kept all the custom text that a user will see in English here, to hopefully help you assist me better.

    Thanks in advance!

    Thursday, February 21, 2019 2:44 PM

All replies

  • If the language support for PS is not installed then the messages will all be blank.


    \_(ツ)_/

    Thursday, February 21, 2019 3:08 PM
  • Thanks for the reply!

    Now, is it possible to download the language support? If yes, is it possible to do so within a PS script?

    I am new to PS, so appologies if this is common knowlege.

    Friday, February 22, 2019 9:34 AM
  • I don't think so.  I believe you have to have installed the correct language version of Windows. You can try to install the language pack for the language.

    I don't think PS comes in any language but English.


    \_(ツ)_/

    Friday, February 22, 2019 9:46 AM
  • I just now had a error message in Norwegian, withouth the "Using-Culture" function. I have also seen Czech and Spanish errors in PS from other examples while researching this. 

    By the looks of it, it seemes like you are correct in the way that it needs the correct language pack for Windows.
    In that case I have the correct language pack, but I still dont understand why the scripts supresses errors with the "Using-Culture" function.

    Friday, February 22, 2019 9:51 AM
  • Some modules may have languages.

    Look in $pshome for language folders.  You should see "en-US" and others in that format if the base PowerShell has language support installed for other languages.

    Module folders also have language folders.  You ca have a language folder for a module but not for other modules or PS>  The language setting determines which language folder to use.


    \_(ツ)_/

    Friday, February 22, 2019 9:59 AM