PowerShell constrained language mode prevents PowerShell from accessing native API functions. PowerShell can still be used in this mode, but will report an error if a script attempts to use native API functions. Running PowerShell in this mode prevents a lot of offensive security scripts from executing.
It should be noted that an attacker may be able to disable constrained mode, however it at least provides an extra layer of defence.
You can check the current status on constrained mode by executing;
To configure constrained mode for testing , the following command can be used;
$ExecutionContext.SessionState.LanguageMode = "ConstrainedLanguage"
To permanently configure constrained mode, create an environment variable called “__PSLockDownPolicy” and set the value to 4:
This setting could also be configured by setting a GPO for the environment variable.
PowerShell Version 2
Constrained mode is not supported in PowerShell version 2. Since this version is installed by default on Windows 10, you will want to remove this feature to prevent an attacker from utilising that version of PowerShell to get past constrained mode.
To check if PowerShell version 2 is enabled, execute the following in an elevated command prompt:
Get-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2
To disable PowerShell version 2, execute the following:
Disable-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root