Functions/Validations/Test-PsLanguageMode.ps1

<#
    .SYNOPSIS
    Tests if the PowerShell session is running in FullLanguage mode.
    .DESCRIPTION
    The PowerShell session can be restricted by an GPO AppLocker policy.
    Test with this cmdlet if the session is restricted or is running in FullLanguage mode.
 
    Returns $true if the session is running in FullLanguage mode and $false when not.
    .EXAMPLE
    Test-PsLanguageMode
    .EXAMPLE
    # Returns either $true or $false but supresses the warning when the session is not running in FullLanguage mode.
    Test-PsLanguageMode -WarningAction SilentlyContinue
    .EXAMPLE
    # Log a warning when the session is not running in FullLanguage mode but ignore the $false output.
    Test-PsLanguageMode | Out-Null
    .EXAMPLE
    Test-PsLanguageMode -Verbose | Out-Null
#>


function Test-PsLanguageMode {
    [CmdletBinding()]
    [OutputType([bool])]
    param()

    if ( $($ExecutionContext.SessionState.LanguageMode) -ne 'FullLanguage') {
        
        $msg = "Task cannot be executed. Current LanguageMode is {0}, this should be FullLanguage." -f
                    $($ExecutionContext.SessionState.LanguageMode)
        $msg += "Make sure that the AppLocker policy is disabled to execute this task."

        Write-Warning $msg
        return $false
    }

    Write-Verbose 'PowerShell session language mode is FullLanguage. Session is not restricted by an AppLocker GPO policy.'
    return $true
}

Export-ModuleMember -Function Test-PsLanguageMode