List SharePoint Services on Server using PowerShell

Manage Services on Server shows which SharePoint service is running on a particular server. You can only select 1 server and you won’t get a quick overview of all the services per server. I have created the below script to create a .html file which shows each server and their active or inactive service.

The following script can be copied into notepad and saved as a .ps1 file. Just execute the script to create a .HTML file. When you run the script, it will ask for an export location. This folder does not have to exist on your harddrive. This has been created and tested for SharePoint 2013 and haven’t tested this yet for SharePoint 2010.

#Import SharePoint PowerShell Modules
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Request the location to store the HTML file
$ExportLocation = Read-Host "Enter the location to store the HTML file. (eg. C:\temp). This directory will be created if it doesn't exist"

Function ListServicesOnServer($path)
{
#Check if directory exists or create the directory
if((Test-Path $path) -eq $false)
{
mkdir $path
write-host "Folder created" -foregroundcolor yellow
}
else
{
write-host "Folder already exists" -foregroundcolor yellow
}

#create an unique name
$date = get-date
$today = $date.ToString("ddMMyyyy_HHmm")
$HTMLpath = "$($path)\ServicesOnServer_$($today).html"

#Create HTML File for the information
New-Item -ItemType file $HTMLpath -force | out-null
add-content -value "<html><body><h1>Services on Server</h1><br />" -path $HTMLpath

#Try / Catch statement to get the information
try
{
#Get the SharePoint servers in the farm
$servers = Get-SPServer | where {$_.Role -ne "Invalid"}

#Create an HTML Table and headers
add-content -value "<table border='1' style='font-family: Calibri, sans-serif'>
<tr>
<th style='background-color:blue; color:white'>Service</th>" -path $HTMLpath
$servers | %{Add-Content $HTMLpath "<th style='background-color:blue; color:white'>$($_.Address)</th>"}
add-content -value "</tr><tr>" -path $HTMLpath

#list all services using 1 server
$services = get-spserviceinstance -server $servers[0]

foreach($service in $services)
{
$serviceTypeName = $service.TypeName | sort-object
Add-Content $HTMLpath "<td>$($service.TypeName)</td>"
$servicesOnServers = get-spserviceinstance | where-object {$_.TypeName -eq $serviceTypeName} | %{Add-Content $HTMLpath "<td>$($_.status)</td>"}
Add-Content $HTMLpath "<tr></tr>"
}

add-content -value "</table></body></html>" -path $HTMLpath
write-host "Script Done" -foregroundcolor green
}
catch
{
write-host "$($_.Exception.Message)" -foregroundcolor red
}
}

ListServicesOnServer($ExportLocation)

Manual

You should already have created a .ps1 file and saved this to a predefined location:

ListServicesOnServer1

Run PowerShell as administrator and run the following command:

& “C:\Temp\ListServicesOnServer.ps1”

ListServicesOnServer2

Press enter and fill in a location:

ListServicesOnServer3

Press enter:

ListServicesOnServer4

The output should look like below:

ListServicesOnServer5

Increase SharePoint Workflow performance and reliability

We encountered several scenario’s where workflows did not start correctly or the workflow did not continue after a pause action. 1 error we have seen is as follows:

AutoStart Workflow: Microsoft.SharePoint.SPException —> System.Runtime.InteropServices.COMException (0x8102008A): <nativehr>0x8102008a</nativehr><nativestack></nativestack>

at Microsoft.SharePoint.Library.SPRequestInternalClass.AddWorkflowToListItem(String bstrUrl, String bstrListName, Int32 lItemID, Int32 lItemLevel, Int32 lItemVersion, Guid workflowPackageId, Guid& pWorkflowInstanceId, Guid workflowTaskListId, String bstrStatusFieldInternalName, Int32 lAuthorId)

at Microsoft.SharePoint.Library.SPRequest.AddWorkflowToListItem(String bstrUrl, String bstrListName, Int32 lItemID, Int32 lItemLevel, Int32 lItemVersion, Guid workflowPackageId, Guid& pWorkflowInstanceId, Guid workflowTaskListId, String bstrStatusFieldInternalName, Int32 lAuthorId)     –

— End of inner exception stack trace —

at Microsoft.SharePoint.Workflow.SPWinOeEngine.CreateWorkflow(Object context, SPWorkflowAssociation association, SPWorkflowEvent startEvent, Boolean bCreateOnly)

at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflowElev(Object context, SPWorkflowAssociation association, DateTime elevationTimeUtc, SPWorkflowEvent startEvent, SPWorkflowRunOptions runOptions)

at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.<>c__DisplayClass1.<AutoStartWorkflow>b__0(SPSite superUserSite, SPWeb superUserWeb)

I have collected a few settings that can be changed to increase performance or the reliability of Workflows in SharePoint.

1. Increase Throttle Size
2. Increase Batch Size
3. Time-Out
4. Workflow Timer interval
5. Event Delivery Throttle
6. Central Administration Time-Out

1. Increase Throttle Size

The workflow throttle setting controls how many workflows can be processed at any one time on the entire server farm

Use the following command to get the default value

stsadm -o getproperty -pn workflow-eventdelivery-throttle

You can change this value with the following command

stsadm -o setproperty -pn workflow-eventdelivery-throttle -pv “25”

image

2. Increase Batch Size

Batch size property controls how many work items waiting to be processed by the timer service will be executed in each run

Run the following command for the default value

stsadm -o getproperty -pn workitem-eventdelivery-batchsize

Run the following command to change this value

stsadm -o setproperty -pn workitem-eventdelivery-batchsize -pv “200”

image

Next start Central Administration and navigate to “Manage services on server”

image

Click on “Microsoft SharePoint Foundation Workflow Timer Service”

image

image

Also change this setting to for example 200

3. Time-Out

Timeout specifies the maximum time which can be taken to complete the workflow timer job in minutes.

Run the following command for the default value

stsadm -o getproperty -pn workflow-eventdelivery-timeout

Run the following command to change this value

stsadm -o setproperty -pn workflow-eventdelivery-timeout -pv “10”

image

4. Workflow Timer interval

Workflow timer Interval shows how often SPtimer job should run to process workflow items.

Use the following command to get the default value

stsadm -o getproperty -propertyname “job-workflow” -url https://portal.sharepointfire.com

You can change this value with the following command

stsadm -o setproperty -propertyname “job-workflow” -propertyvalue “every 2 minutes between 0 and 59” -url https://portal.sharepointfire.com

image

5. Event Delivery Throttle
The WorkflowEventDeliveryThrottle parameter is used to throttle the workflow events

Run the following command for the default value

stsadm -o getproperty -pn workflow-eventdelivery-throttle -url https://portal.sharepointfire.com

Run the following command to change this value

stsadm -o setproperty -pn workflow-eventdelivery-throttle -url https://portal.sharepointfire.com -pv “30”

image

6. Central Administration Time-Out

This is the same procedure as described in http://www.sharepointfire.com/2013/03/cannot-display-the-webpage-while-creating-a-web-application-in-sharepoint/

Unlock SharePoint Site Collections

You can lock or unlock SharePoint Site Collections manually but it’s also possible your Site Collection gets locked by SharePoint. A Site Collection backup for example locks the Site Collection during backup and this lock will remain in place if the backup could not be completed. Your Site Collection can also be in Maintenance Mode which makes it unable to set the state to “Not Locked” without PowerShell.

Which Site Collections are locked?

You can run the following script to find out in which state your Site Collection is

#Add PowerShell Snapin
Add-pssnapin Microsoft.SharePoint.Powershell -ErrorAction silentlycontinue

#Get all Site Collections
$SiteCollections = get-spsite -limit all

#Loop through all site collections
foreach($SiteCollection in $SiteCollections)
{
#Remove "SPSite Url=" from variable
$Url = $SiteCollection.url.Replace("SPSSite Url=","")

#Verify the properties from the Site Collection
if ($SiteCollection.ReadOnly -eq $false -and $SiteCollection.ReadLocked -eq $false -and $SiteCollection.WriteLocked -eq $false)
{
write-host "$Url : Unlocked" -foregroundcolor Green
}
elseif ($SiteCollection.ReadOnly -eq $false -and $SiteCollection.ReadLocked -eq $false -and $SiteCollection.WriteLocked -eq $true)
{
write-host "$Url : Adding content prevented" -foregroundcolor yellow
}
elseif ($SiteCollection.ReadOnly -eq $true -and $SiteCollection.ReadLocked -eq $false -and $SiteCollection.WriteLocked -eq $true)
{
write-host "$Url : Read-only" -foregroundcolor Red
}
elseif ($SiteCollection.ReadOnly -eq $null -and $SiteCollection.ReadLocked -eq $null -and $SiteCollection.WriteLocked -eq $null)
{
write-host "$Url : No access" -foregroundcolor yellow
}
elseif ($SiteCollection.MaintenanceMode -eq $true)
{
write-host "$Url : Maintenance Mode" -foregroundcolor red
}
}

Output

image

Unlocking the Site Collection

By Central Administration

1. Open Central Administration

2. Click on ‘Application Management’

3. Click on ‘Configure quotas and locks’

4. Navigate to the locked site collection

image

5. Unlock the Site Collection

image

6. Click on OK

By PowerShell

Run the following script to unlock a single Site Collection or add this line to the above script to unlock the site collection immediately.

Set-SPSite -Identity “<SiteCollection>” -LockState Unlock

image

Maintenance Mode

The following warning is viewable on the site when the Site Collection is in maintenance mode

clip_image002

and you are unable to modify the lock manually or with the normal PowerShell commands.

image

You can only disable maintenance mode for a Site Collection with PowerShell by running the following commands

$Admin =  new-object Microsoft.SharePoint.Administration.SPSiteAdministration(‘<SiteCollectionURL>’)
$Admin.ClearMaintenanceMode()