Post

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 […]

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

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Archive