There are some mysterios errors on my SharePoint farm. After reading tons of log files I found some hints to problems with the “Session State Service” of SharePoint 2010.
I found this Cmdlets in PowerShell for controlling this service:
I tried to enable the service with the first Cmdlet. – This was the resulting error:
Error message: “Microsoft SharePoint Server session state could not find the Session State Service. Contact your farm administrator.”
There is no information about this error in the internet. (Till now )
MY SOLUTION FOR MY PROBLEM (may be it does not help you in your special situation. It’s “experimental”!!!):
I created a PowerShell script for re-creating the Session State Service and its Service Application.
Before you go on: Make sure, the Windows service “ASP.NET State Service” is running. (I set it to start automatically during system startup.)
This is the resulting script:
#region Check x64 host
if( [System.IntPtr]::Size-ne8) {
Write-Error"Please use a x64 PowerShell host!"return
}
#endregion#region Load SharePoint SnapIn and DLL
Remove-PSSnapinMicrosoft.SharePoint.PowerShell-ErrorActionSilentlyContinueAdd-PSSnapinMicrosoft.SharePoint.PowerShell-ErrorActionSilentlyContinue#Check available SharePoint Cmdletsif( (Get-Command-Noun SPWeb*) -eq$null ) {
Write-Error"SharePoint SnapIn not loaded. SharePoint cmdlets missing!"return
}
#endregioncls$farm= [Microsoft.SharePoint.Administration.SPFarm]::Local$services=$farm.get_Services() #get all SharePoint services$sessionStateService= ($services | ? { $_.TypeName -like"*session state*" } ) #find the existing Session State Service -> it was "NULL" for me!if( $sessionStateService-eq$null ) {
#Recreate the Service$newSessionStateService=New-ObjectMicrosoft.Office.Server.Administration.SessionStateService ("", $farm)
$newSessionStateService.Id= [System.Guid]::NewGuid()
$newSessionStateService.Name=[String]::Empty$newSessionStateService.Update()
$farm.Update()
$newSessionStateService.Provision()
$newSessionStateService.Name=[String]::Empty$newSessionStateService.Update()
}
$services=$farm.get_Services()
$sessionStateService= ($services | ? { $_.TypeName -like"*session state*" } )
$servers=(Get-SPServer)
#Create service instances on all application servers of the SharePoint farm$servers | % {
if( $_.Role -eq"Application" ) {
$currentSessionStateSvcOnServer= ($_.ServiceInstances | ? { $_.TypeName -like"*session state*" } )
if( $currentSessionStateSvcOnServer-eq$null ) {
#write-host $_.Name $server.Role $_.gettype().fullname#To create a service instance you must use a "protected" constructor [type]$t="Microsoft.SharePoint.Administration.SPServiceInstance"-as"Type"$p= @( ("string"-as [Type]), ("Microsoft.SharePoint.Administration.SPServer"-as [Type]),
("Microsoft.SharePoint.Administration.SPService"-as [Type]) )
$c=$t.GetConstructor([System.Reflection.BindingFlags]::NonPublic-bor [System.Reflection.BindingFlags]::Instance,$null, $p, $null)
#these are the parameters for creating a service instance by using the protected constructor [Object[]]$params= @([Object]"Session State Service Instance",
[Object]([Microsoft.SharePoint.Administration.SPFarm]::Local.Servers[$_.Name]),
[Object]([Microsoft.SharePoint.Administration.SPFarm]::Local.Services[$sessionStateService.Id]))
$newSvcInstance=$c.Invoke($params)
#update & provisioning$newSvcInstance.Update()
$newSvcInstance.Provision()
}
}
}
if( (Get-SPSessionStateService-ErrorActionSilentlyContinue) -ne$null ) {
Write-Host"Successfull :-)"-ForegroundColorGreen
} else {
Write-Host"Failed :-("-ForegroundColorRed
}
After that, the “Enable-SPSessionStateService” works:
(Spend me 1 1/2 days.)
You can use this script to delete the Session State Service, e.g. if some script parts does not work as expected. ONCE MORE: USE IT CAREFULLY AND AT YOUR OWN RISK!!!
If you want to set the SharePoint 2010 Enterprise Search Service Application "Default Content Access Account" by using PowerShell you can use this script:
$searchapp= Get-SPEnterpriseSearchServiceApplication "Search Service Application" $c=New-ObjectMicrosoft.Office.Server.Search.Administration.Content($searchapp) $c.SetDefaultGatheringAccount($crawlUser, (ConvertTo-SecureString$crawlPwd-AsPlainText-force))
($crawlUser is – of cause – the login of the account and $crawlPwd is the password in plain text)
For a current project I want to create a “master script” that contains another compressed PowerShell script. This compressed script contains some informations – server names, network share names – that should be as unreadable as possible for normal users. This script is executed during user logon.
I created two scripts
"compress.ps1"
"execute.ps1"
The first script is used to compress a script. The second one is used to execute the compressed script.
This executes the following code snipped from the script above:
Write-Host"This is a test"Get-Service A*
The output is:
This is a test
Status Name DisplayName
------ ---- -----------
Stopped AeLookupSvc Anwendungserfahrung
Running AESTFilters Andrea ST Filters Service
Stopped ALG Gatewaydienst auf Anwendungsebene
Stopped AppIDSvc Anwendungsidentität
Stopped Appinfo Anwendungsinformationen
Running Apple Mobile De... Apple Mobile Device
Stopped AppMgmt Anwendungsverwaltung
Stopped aspnet_state ASP.NET-Zustandsdienst
Running AudioEndpointBu... Windows-Audio-Endpunkterstellung
Running AudioSrv Windows-Audio
Stopped AxInstSV ActiveX-Installer (AxInstSV)
If you load an CSV file with import-csv you will end up with an object of type System.Management.Automation.PSCustomObject. It’s an array.
In such a case I liked to use such an imported file or especially the imported data with the correct object type.
Therefore I created an generic “cast” function in generic PowerShell that can be used for casting with other types.
See the following PowerShell script. The function “Get-CastedObject” takes to parameters:
1) the source array
2) the result object type as string
In the following sample the script creates a CSV file and reads the content of the file during the next run. After loading the data the objects of the array will be “casted” to the correct data type.
Therefore the cast function looks for the “property” object members and tries to assign them to the new created object of the expected result type.
I’m sure there are several opportunities for improvements. Please let me know!
$outfile=“C:tempcast-test.csv“
Add-Type@’ public class ResultObj
{
public string Test1 = “”;
public string Test2 = “”;
public bool Test3 = false;
public int Test4 = 0;
} ‘@
After updating the SharePoint Foundation 2010 Server of our company to SharePoint Server 2010 I got this error in the Event Viewer:
Load control template file /_controltemplates/TaxonomyPicker.ascx failed:
Could not load type 'Microsoft.SharePoint.Portal.WebControls.TaxonomyPicker'
from assembly 'Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.
I could solve this error by re-enabling the corresponding feature using this PowerShell script:
Note: The first to lines of the script enable are “standard lines of code” for me. They enable SharePoint PowerShell support if you use the Script without “SharePoint 2010 Management Shell”.