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
    }     

Monday, January 4, 2016

SharePoint PowerShell Command After Update, CU, or Upgrade Required | psconfig | inplace | b2b

SharePoint PowerShell Command After Update

After running SharePoint updates, CU, or patches the following command must be run on every SharePoint server, one server at a time, to ensure the update has been fully implemented.  Until the command is run and completed successful the update is not applied to the server even though the update bits have been installed on the server.



#When running straight from the PowerShell ISE add in the reference to SharePoint
Add-PSSnapin microsoft.sharepoint.powershell

#For a small update the following basic command can be used.  It has 4 configuration steps.
PSConfig.exe -cmd upgrade -inplace b2b -wait -force


#For major releases the command below should be used.  It has 6 to 7 configuration steps.
PSConfig.exe -cmd upgrade -inplace b2b -force -cmd applicationcontent -install -cmd installfeatures



#If errors occur or the command does not complete successfully the following script can be used.

stsadm -o setproperty -pn command-line-upgrade-running -pv Yes

iisreset

PSConfig.exe -cmd upgrade -inplace b2b -wait -force

PSConfig.exe -cmd upgrade -inplace b2b -force -cmd applicationcontent -install -cmd installfeatures

# if the above commands still fail, open IIS on server and make sure it is started and the sites are running
# somtimes the upgrade process stops the sites and doesn't start them back up



# as a last ditch effort, if the commands continues to fail, remove Microsoft SharePoint Foundation Web Application feature in CA for the server.
# This will remove the app pools and IIS sites.  It will also delete any custom changes that you have made to your web.config files.  It may also
# retract and turn off farm solutions.  That is why this step should only be used when nothing else works.



# Example of the basic command failing. performs 4 tasks.  If the basic upgrade command fails as seen below.  You can try to track down the issue through the logs but usually running the longer command with 7 steps will succeed.

Performing configuration task 3 of 4
Upgrading SharePoint Products...

Failed to upgrade SharePoint Products.

An exception of type Microsoft.SharePoint.Administration.SPUpdatedConcurrencyException was thrown.  Additional exception information: An update conflict has occurred,
 and you must re-try this action. The object SPUpgradeSession Name=Upgrade-20160607-105424-415 was updated by USERNAME, in the PSCONFIG (27172) process, on ma
chine SERVERNAME.  View the tracing log for more information about the conflict.

Total number of configuration settings run: 3
Total number of successful configuration settings: 2
Total number of unsuccessful configuration settings: 1
Successfully stopped the configuration of SharePoint Products.
Configuration of SharePoint Products failed.


# Basic version
PSConfig.exe -cmd upgrade -inplace b2b -wait -force
# Switch to the longer version
PSConfig.exe -cmd upgrade -inplace b2b -force -cmd applicationcontent -install -cmd installfeatures

# The upgrade configuration steps completed successfully.  I'm not sure what caused the conflict and why the 4 step process failed.  All that really matters is the longer process was successful.

Successfully completed the SharePoint Products configuration.

Total number of configuration settings run: 6
Total number of successful configuration settings: 6
Total number of unsuccessful configuration settings: 0
Successfully stopped the configuration of SharePoint Products.
Configuration of the SharePoint Products has succeeded.




Saturday, January 2, 2016

Welcome to My Blog. It is Time to Give Back.

I figured it was finally time to start sharing small snippets of code and other details that I have used to solve many IT problems.  If it wasn't for blogs finding a solution to one off problems would be much more difficult.  So I've decided to give back.


Stephen J. Wire