MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4if ($IsWindows)5{6 Import-Module HelpersCommon7 8 $code = @'9 10 #region Using directives11 12 using System;13 using System.Management.Automation;14 15 #endregion16 17 /// <summary>Adds a new type to the Application Domain</summary>18 [Cmdlet("Invoke", "LanguageModeTestingSupportCmdlet")]19 public sealed class InvokeLanguageModeTestingSupportCmdlet : PSCmdlet20 {21 [Parameter()]22 public SwitchParameter EnableFullLanguageMode { get; set; }23 24 [Parameter()]25 public SwitchParameter SetLockdownMode { get; set; }26 27 [Parameter()]28 public SwitchParameter RevertLockdownMode { get; set; }29 30 protected override void BeginProcessing()31 {32 if (EnableFullLanguageMode)33 {34 SessionState.LanguageMode = PSLanguageMode.FullLanguage;35 }36 37 if (SetLockdownMode)38 {39 Environment.SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", EnvironmentVariableTarget.Machine);40 }41 42 if (RevertLockdownMode)43 {44 Environment.SetEnvironmentVariable("__PSLockdownPolicy", null, EnvironmentVariableTarget.Machine);45 }46 }47 }48'@49 50 if (-not (Get-Command Invoke-LanguageModeTestingSupportCmdlet -ErrorAction Ignore))51 {52 $moduleName = Get-RandomFileName53 $moduleDirectory = Join-Path $TestDrive\Modules $moduleName54 if (-not (Test-Path $moduleDirectory))55 {56 $null = New-Item -ItemType Directory $moduleDirectory -Force57 }58 59 try60 {61 Add-Type -TypeDefinition $code -OutputAssembly $moduleDirectory\TestCmdletForConstrainedLanguage.dll -ErrorAction Ignore62 } catch {}63 64 Import-Module -Name $moduleDirectory\TestCmdletForConstrainedLanguage.dll65 }66}67 