Pages

Thursday, September 7, 2017

PowerShell - Only core types are supported in this language mode - ISE Doesn't Work - Constrained Language Mode - PSLockDownPolicy

I recently encountered a client whose security team had been very proactive in locking everything down, not necessary a bad thing but it can make simple tasks very difficult at times.

For example, if you are trying to run PowerShell on a SharePoint server but receive an error message such as "Only core types are supported in this language mode" or if you are trying to a PS1 file in debug mode in the PowerShell ISE but get the message that it cannot find the file.  If you are a local admin, farm admin, SPShellAdmin, and any other type of admin you still might encounter this situation.  If you have all those rights but can't create any typed variable or run the PowerShell ISE in debug mode; then that SharePoint environment may be operating in Constrained Language Mode.

This problem does not appear to be very common but is very frustrating when the ISE can't even run a script or import modules.  It took me awhile to track down the information and find a work around so I am adding a post about it which I hope helps someone else.

The easiest way to check if this is the problem is to look in the registry.  Here is the specific key.

$Path = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$Property = "__PSLockdownPolicy"



0 = Full Language
1 = Full Language
2 = Full Language
3 = Full Language
4 = Constrained Language Mode
5 = Constrained Language Mode
6 = Constrained Language Mode
7 = Constrained Language Mode
8 = Full Language

I've added a PowerShell script that will pull the registry key and write out the result.  If no registry key is set, then the server should be operating in Full Language Mode.


try{
    $Path = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
    $Property = "__PSLockdownPolicy"
    $result = Get-ItemProperty -Path $path -Name $Property
    $PolicyValue = $result.__PSLockdownPolicy

    $LockdownPolicy = switch ($PolicyValue)
    {
            0 {"Full Language Mode"; Break}
            1 {"Full Language Mode"; Break}
            2 {"Full Language Mode"; Break}
            3 {"Full Language Mode"; Break}
            8 {"Full Language Mode"; Break}
            4 {"Constrained Language Mode"; Break}
            5 {"Constrained Language Mode"; Break}
            6 {"Constrained Language Mode"; Break}
            7 {"Constrained Language Mode"; Break}
    }

           Write-Host "Lockdown Policy Value: $PolicyValue$LockdownPolicy" -ForegroundColor Yellow
}
Catch{
   if($result -eq $null){
        Write-Host = "No PSLockdownPolicy found. Should be operating in Full Lanaguge Mode" -ForegroundColor Yellow
    }

}
     



No comments:

Post a Comment