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
    }

}
     



Monday, May 1, 2017

SharePoint Version and Edition Build Numbers Using PowerShell

SharePoint Version and Edition Build Numbers Using PowerShell


I compiled this script to easily determine which edition and build number a SharePoint farm is running.  Part of it came from a TechNet article.  I added in the GUIDs for the older versions.  Just run the entire script and it produce the information in yellow at the end.


Add-PSSnapin microsoft.sharepoint.powershell

$SharePointEditionGuid = (Get-SPFarm).Products
$SharePointEdition = switch ($SharePointEditionGuid)
    {
        5DB351B8-C548-4C3C-BFD1-82308C9A519B {"The Installed SharePoint Edition is SharePoint 2016 Trail Edition."; Break}
        4F593424-7178-467A-B612-D02D85C56940 {"The Installed SharePoint Edition is SharePoint 2016 Standard Edition."; Break}
        716578D2-2029-4FF2-8053-637391A7E683 {"The Installed SharePoint Edition is SharePoint 2016 Enterprise Edition."; Break}
        84902853-59F6-4B20-BC7C-DE4F419FEFAD {"The Installed SharePoint Edition is Project Server 2010 Trial Edition."; Break}
        ED21638F-97FF-4A65-AD9B-6889B93065E2 {"The Installed SharePoint Edition is Project Server 2010 Edition."; Break}
        BC4C1C97-9013-4033-A0DD-9DC9E6D6C887 {"The Installed SharePoint Edition is Search Server 2010 Trial Edition."; Break}
        08460AA2-A176-442C-BDCA-26928704D80B {"The Installed SharePoint Edition is Search Server 2010 Edition."; Break}
        BEED1F75-C398-4447-AEF1-E66E1F0DF91E {"The Installed SharePoint Edition is SharePoint Foundation 2010 Edition."; Break}
        1328E89E-7EC8-4F7E-809E-7E945796E511 {"The Installed SharePoint Edition is Search Server Express 2010 Edition."; Break}
        B2C0B444-3914-4ACB-A0B8-7CF50A8F7AA0 {"The Installed SharePoint Edition is SharePoint Server 2010 Standard Trial Edition."; Break}
        3FDFBCC8-B3E4-4482-91FA-122C6432805C {"The Installed SharePoint Edition is SharePoint Server 2010 Standard Edition."; Break}
        88BED06D-8C6B-4E62-AB01-546D6005FE97 {"The Installed SharePoint Edition is SharePoint Server 2010 Enterprise Trial Edition."; Break}
        D5595F62-449B-4061-B0B2-0CBAD410BB51 {"The Installed SharePoint Edition is SharePoint Server 2010 Enterprise Edition."; Break}
        926E4E17-087B-47D1-8BD7-91A394BC6196 {"The Installed SharePoint Edition is Office Web Applications 2010 Edition."; Break}
        35466B1A-B17B-4DFB-A703-F74E2A1F5F5E {"The Installed SharePoint Edition is Project Server 2013 Edition."; Break}
        BC7BAF08-4D97-462C-8411-341052402E71 {"The Installed SharePoint Edition is Project Server 2013 Preview Edition."; Break}
        9FF54EBC-8C12-47D7-854F-3865D4BE8118 {"The Installed SharePoint Edition is SharePoint Foundation 2013 Edition."; Break}
        C5D855EE-F32B-4A1C-97A8-F0A28CE02F9C {"The Installed SharePoint Edition is SharePoint Server 2013 Standard Edition."; Break}
        B7D84C2B-0754-49E4-B7BE-7EE321DCE0A9 {"The Installed SharePoint Edition is SharePoint Server 2013 Enterprise Edition."; Break}
        D6B57A0D-AE69-4A3E-B031-1F993EE52EDC {"The Installed SharePoint Edition is Microsoft Office Web Apps Server 2013 Edition."; Break}
    }
         
if($SharePointEdition -eq $null)
    {
        Write-Host "The SharePoint Edition can't be determined." -ForegroundColor Red
    }
else
    {
        Write-Host $SharePointEdition -ForegroundColor Yellow
        Write-Host "The Build Version:" (Get-SPFarm).buildversion -ForegroundColor Yellow
    }