Listing Services on SharePoint Farm by Server using PowerShell


I ran into Todd Klindt at SPTechCon today and he presented me with an interesting problem.  How do you display a list of SharePoint services running in a farm top to bottom and list of servers in the farm left to right in a table indicating which are running using PowerShell.  So I thought about it for a bit and came up with this which is not exactly what he was looking for but close:

clear-host
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$services = new-object system.collections.sortedlist
$servers = (get-spfarm).servers
foreach ($server in $servers)
{
    foreach($service in $server.serviceinstances)
    {
        if ($service.status = "Online")
        {
            $s = $service.typename
            if ($services.contains($s))
            {
                $serverlist = $services[$s]
                $servername = $server.name
                $services[$s] = "$serverlist - $servername"
            }
            else
            {
                $services[$s] = $server.name
            }
        }
    }
}
$services

The output of this script looks something like this:

Name                           Value     
----                           -----     
Access Database Service        demo      
Application Discovery and L... demo      
Application Registry Service   demo      
Business Data Connectivity ... demo      
Central Administration         demo      
Claims to Windows Token Ser... demo      
Document Conversions Launch... demo      
Document Conversions Load B... demo      
Excel Calculation Services     demo      
Information Management Poli... demo      
Lotus Notes Connector          demo      
Managed Metadata Web Service   demo      
Microsoft SharePoint Founda... demo      
Microsoft SharePoint Founda... demo      
Microsoft SharePoint Founda... demo      
Microsoft SharePoint Founda... demo      
Microsoft SharePoint Founda... demo      
Microsoft SharePoint Founda... demo      
Microsoft SharePoint Founda... demo      
Microsoft SharePoint Founda... demo      
Microsoft SharePoint Founda... demo      
Microsoft SharePoint Founda... demo       
PerformancePoint Service       demo      
Portal Service                 demo      
Search Administration Web S... demo      
Search Query and Site Setti... demo      
Secure Store Service           demo      
Security Token Service         demo      
SharePoint Foundation Search   demo - demo
SharePoint Server Search       demo - demo
SSP Job Control Service        demo      
User Profile Service           demo      
User Profile Synchronizatio... demo      
Visio Graphics Service         demo      
Web Analytics Data Processi... demo      
Web Analytics Web Service      demo      
Word Automation Services       demo  

I only have one server in my development farm, but you should see a list of servers after each service that have the service running.

Advertisements

5 thoughts on “Listing Services on SharePoint Farm by Server using PowerShell

  1. challenge accepted!

    $services = new-object system.collections.sortedlist
    Get-SPServer | Where-Object { $_.Role -match ‘Application’ } | %{ $_.serviceinstances | % { if (!($services.contains($_.typename))){ $services[$_.typename] = $_.typename} }}
    $servers = Get-SPServer | Where-Object { $_.Role -match ‘Application’ }
    $tabName = “Services Table”
    $table = New-Object system.Data.DataTable “$tabName”
    $table.columns.add( (New-Object system.Data.DataColumn Service,([string])))
    $table.PrimaryKey = $table.Columns[“Service”]
    $servers | %{ $table.columns.add( (New-Object system.Data.DataColumn $_.Name,([string])) ) }
    $services.Keys | %{ $table.Rows.Add( ($table.NewRow().Service = $_)) }
    foreach($server in $servers){
    $server.serviceinstances | %{ if ($_.status -eq “Online” ) {$table.Rows.Find($_.typename)[$server.Name] = “Online”} }
    }
    $table | ft -AutoSize -property *

  2. Hi,

    I have used your script but issue is that i am not able to run the script with other PowerShell commands. Below is my script for which i am trying to get output

    #***********************************************
    #Display Current System Time
    #***********************************************
    Get-Date
    #**********************************************
    #Displays SharePoint Services on Services.msc
    #**********************************************
    Get-Service W3SVC, SPAdminV4, SPSearch4, SPUserCodeV4, SPTraceV4, SPWriterV4, WebAnalyticsService,ProfSvc |Select DisplayName, Status
    #***********************************************
    #Within the Windows PowerShell we can add SharePoint snap in to run SP cmdlets
    #***********************************************
    Add-PSSnapin Microsoft.SharePoint.PowerShell
    #*****************************
    #List all the Webapplications
    #*****************************
    Get-SPWebApplication | Select URL, Status
    #*************************
    #List all SP Services Status on all servers in the FARM where it is hosted
    #*************************
    Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
    $services = new-object system.collections.sortedlist
    $servers = (get-spfarm).servers
    foreach ($server in $servers)
    {
    foreach($service in $server.serviceinstances)
    {
    if ($service.status = “Online”)
    {
    $s = $service.typename
    if ($services.contains($s))
    {
    $serverlist = $services[$s]
    $servername = $server.name
    $services[$s] = “$serverlist – $servername”
    }
    else
    {
    $services[$s] = $server.name
    }
    }
    }
    }
    $services

    #********************************
    #List All Service Applications Status
    #********************************
    Get-SPServiceApplication | Select URL, Status

    #*******************************************
    #Adds IIS snap in, We don’t have IIS Snap in installed
    #*******************************************

    Import-Module WebAdministration
    Get-WebItemState IIS:\AppPools\11ca010994114457bbf73ec80bcd7b85
    Get-WebItemState IIS:\AppPools\11ca010994114457bbf73ec80bcd7b85
    Get-WebItemState IIS:\AppPools\582e9ccb5b6041289eb20cf6dc7a0dda
    Get-WebItemState IIS:\AppPools\bd5c0c275496426a9b0afdfc6324a4fd
    Get-WebItemState IIS:\AppPools\Classic .NET AppPool
    Get-WebItemState IIS:\AppPools\SharePoint – 2100
    Get-WebItemState IIS:\AppPools\SharePoint – 55555
    Get-WebItemState IIS:\AppPools\SharePoint – 80
    Get-WebItemState IIS:\AppPools\SharePoint Central Administration v4
    Get-WebItemState IIS:\AppPools\SharePoint Web Services Root

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s