Contact Info

Crumbtrail

ActiveXperts.com » Network Monitor » Scripts » Custom Script

mssharepointserver.ps1 - powershell script by ActiveXperts Software

mssharepointserver.ps1 checks whether MS SharePoint Server is running; it checks services, processes and performance counters.

Use mssharepointserver.ps1 directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select mssharepointserver.ps1. Configure the required parameter, or press 'Load a working sample'.

In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.


mssharepointserver.ps1 script code

#################################################################################
# ActiveXperts Network Monitor PowerShell script, © ActiveXperts Software B.V.
# For more information about ActiveXperts Network Monitor, visit the ActiveXperts 
# Network Monitor web site at http://www.activexperts.com
#################################################################################
# Script:
#     MsSharepointServer.ps1
# Description: 
#     Checks if MS SharePoint Server is running; it checks the SharePoint services 
#     and SharePoint processes
# Declare Parameters:
#     1) strHost (string) - Hostname or IP address of the server you want to check
#     2) strVersion (string) - Sharepoint Server version
#     3) strAltCredentials (string, optional) - Specify an empty string to use Network Monitor service credentials.
#         To use alternate credentials, enter a server that is defined in Server Credentials table.
#         (To define Server Credentials, choose Tools->Options->Server Credentials)
# Usage:
#     .\MsSharepointServer.ps1 '<Hostname | IP>' '<Version>' '[alt-credentials]'
# Sample:
#     .\MsSharepointServer.ps1 'localhost' '2013'
#################################################################################

# -- Declare Parameters
param ( [string]$strHost = '', [string]$strVersion = '', [string]$strAltCredentials = '' )

# -- Use _activexperts.ps1 with common functions 
. 'C:\Program Files\ActiveXperts\Network Monitor\Scripts\Monitor (ps1)\_activexperts.ps1' 


#################################################################################
# // --- Private Functions section ---
#################################################################################

function getSoftwareInfo( $strVersion, [ref]$lstServices, [ref]$lstProcesses, [ref]$lstPerfCounters )
{
  # Retrieve services, processes and counters associated to the specific version of the software. Entries that start 
  # with '!' are optional services/processes/counters and are not checked by default. Remove '!' mark to enable monitoring those items.
  switch( $strVersion )
  {
    '2013' # Microsoft SharePoint 2013
    {
      $lstServices.value = @( @( 'SPAdminV4', 'SharePoint Administration' ), 
                              @( '!SPTimerV4', 'SharePoint Timer Service' ), 
                              @( '!SPTraceV4', 'SharePoint Tracing Service' ), 
                              @( '!SPUserCodeV4', 'SharePoint User Code Host' ), 
                              @( '!SPWriterV4', 'SharePoint VSS Writer' ), 
                              @( 'MSSQLSERVER', 'SQL Server (MSSQLSERVER)' ),
                              @( '!SQLWriter', 'SQL Server VSS Writer' ),
                              @( '', '' ) )
      $lstProcesses.value = @( 'WSSADMIN.EXE','!OWSTIMER.EXE','!wsstracing.exe', '!SPUCHostService.exe', '!SPWRITER.EXE', 'sqlservr.exe', '!sqlwriter.exe', '' )
      $lstPerfCounters.value = @( @( 'Memory', '', 'Available Bytes', '-gt 104857600' ), 
                                  @( 'Processor', '_TOTAL', '% Processor Time', '-lt 90' ),
                                  @( '', '', '', ''  ) )
      return $AXSUCCESS
    }
    
    '2010' # Microsoft SharePoint 2010
    {
      $lstServices.value = @( @( 'Services=SPAdminV4', 'SharePoint 2010 Administration' ),
                              @( '!SPTimerV4', 'SharePoint 2010 Timer' ),
                              @( 'SPTraceV4', 'SharePoint 2010 Tracing' ),
                              @( '!SPUserCodeV4', 'SharePoint 2010 User Code Host' ),
                              @( '!SPWriterV4', 'SharePoint 2010 VSS Writer' ),
                              @( '!SPSearch4', 'SharePoint Foundation Search V4' ),
                              @( '!OSearch14', 'SharePoint Server Search 14' ),
                              @( 'MSSQLSERVER', 'SQL Server (MSSQLSERVER)' ),
                              @( '', '' ) )                
      $lstProcesses.value = @( 'WSSADMIN.EXE', '!OWSTIMER.EXE', 'wsstracing.exe', '!SPUCHostService.exe', '!SPWRITER.EXE', '!mssearch.exe', '!mssearch.exe','sqlservr.exe', '' )
      $lstPerfCounters.value = @( @( 'Memory', '', 'Available Bytes', '-gt 104857600' ), 
                                  @( 'Processor', '_TOTAL', '% Processor Time', '-lt 90' ),
                                  @( '', '', '', ''  ) )
      return $AXSUCCESS
    }
         
    '2007' # Microsoft Office SharePoint Portal Server 2007
    {
      $lstServices.value = @( @( 'SPSearch', 'Windows SharePoint Services Search' ),
                              @( 'SPTimerV3', 'Windows SharePoint Services Timer' ),
                              @( 'SPTrace', 'Windows SharePoint Services Tracing' ),
                              @( '!SPAdmin', 'Windows SharePoint Services Administration' ),
                              @( '!SPWriter', 'Windows SharePoint Services VSS Writer' ),
                              @( '', '' ) )
      $lstProcesses.value = @( , '' )
      $lstPerfCounters.value = @( @( 'Memory', '', 'Available Bytes', '-gt 104857600' ), 
                                  @( 'Processor', '_TOTAL', '% Processor Time', '-lt 90' ),
                                  @( '', '', '', ''  ) )
      return $AXSUCCESS
    }
      
    '3'    # Windows SharePoint Services 3.0 (framework for MOSS 2007)
    {
      $lstServices.value = @( @( 'SPSearch', 'Windows SharePoint Services Search' ),
                              @( 'SPTrace', 'Windows SharePoint Services Tracing' ),
                              @( '!SPAdmin', 'Windows SharePoint Services Administration' ),
                              @( '!SPWriter', 'Windows SharePoint Services VSS Writer' ),
                              @( '', '' ) )
                
      $lstProcesses.value = @( , '' )
      $lstPerfCounters.value = @( @( 'Memory', '', 'Available Bytes', '-gt 104857600' ), 
                                  @( 'Processor', '_TOTAL', '% Processor Time', '-lt 90' ),
                                  @( '', '', '', ''  ) )

      return $AXSUCCESS
    }
      
    '2003' # Microsoft Office SharePoint Portal Server 200
    {
      $lstServices.value = @( @( 'MSSQL$SHAREPOINTPORTAL', 'MSSQL$SHAREPOINTPORTAL' ),
                              @( 'SPSAdmin', 'SharePoint Portal Administration' ),
                              @( '!', 'SPSAlert', 'SharePoint Portal Alert' ),
                              @( 'SPTimer', 'SharePoint Timer Service' ),
                              @( '!SQLAgent$SHAREPOINTPORTAL', 'SQLAgent$SHAREPOINTPORTAL' ),
                              @( '', '' ) )
      $lstProcesses.value = @( , '' )
      $lstPerfCounters.value = @( @( 'Memory', '', 'Available Bytes', '-gt 104857600' ), 
                                  @( 'Processor', '_TOTAL', '% Processor Time', '-lt 90' ),
                                  @( '', '', '', '' ) )
      return $AXSUCCESS
    }
      
    '2' # Windows SharePoint Services 2.0 (framework for MOSS 2003)
    {
      $lstServices.value = @( @( 'MSSQL$SHAREPOINT', 'MSSQL$SHAREPOINT' ),
                              @( 'SPTimer', 'SharePoint Timer Service' ),
                              @( '', '' ) )
      $lstProcesses.value = @( , '' )
      $lstPerfCounters.value = @( @( 'Memory', '', 'Available Bytes', '-gt 104857600' ), 
                                  @( 'Processor', '_TOTAL', '% Processor Time', '-lt 90' ),
                                  @( '', '', '', ''  ) )
      return $AXSUCCESS
    }
      
    default
    {
      $lstServices.value = @( , @( '', '' ) )
      $lstProcesses.value = @( , '' )
      $lstPerfCounters.value = @( , @( '', '', '', '' ) )
      return $AXERROR
    }
  }
}


#################################################################################
# // --- Main script ---
#################################################################################

# -- Clear screen and clear error
cls
$Error.Clear()
  
# -- Validate parameters, return on parameter mismatch
if( $strHost -eq '' -or $strVesion -eq '' )
{
  $res = 'UNCERTAIN: Parameter error - Usage: .\MsSharepointServer.ps1 "<Hostname | IP>" "<Version>" [alt-credentials]'
  echo $res
  exit
}

# Declare local variables by assigning an initial value to it
$lstServices = $null
$lstProcesses = $null
$lstPerfCounters = $null

$objAltCredentials = $null
$strExplanation = ''

# If alternate credentials are specified, retrieve the alternate login and password from the ActiveXperts global settings
if( $strAltCredentials -ne '' )
{
  # Get the Alternate Credentials object. Function "AxGetCredentials" is implemented in "activexperts.ps1"
  if( ( AxGetCredentials $strHost  $strAltCredentials ([ref]$objAltCredentials) ([ref]$strExplanation) ) -ne $AXSUCCESS )
  {
    echo $strExplanation
    exit
  }
}


# Retrieve product processes/services/performance-counters list
if( ( getSoftwareInfo $strVersion ([ref]$lstServices) ([ref]$lstProcesses) ([ref]$lstPerfCounters) ) -ne $AXSUCCESS )
{ 
  $res = 'ERROR: Version [' + $strVersion + '] is not supported.'
  echo $res
  exit
}

# -- Check services
if( ( AxCheckServices $strHost ([ref]$lstServices) $objAltCredentials ([ref]$strExplanation) ) -ne $AXSUCCESS )
{
  echo $strExplanation
  exit
}

# -- Check processes
if( ( AxCheckProcesses $strHost ([ref]$lstProcesses) $objAltCredentials ([ref]$strExplanation) ) -ne $AXSUCCESS )
{
  echo $strExplanation
  exit
}

# -- Check performance counters
if( ( AxCheckPerfCounters $strHost ([ref]$lstPerfCounters) $objAltCredentials ([ref]$strExplanation) ) -ne $AXSUCCESS )
{
  echo $strExplanation
  exit
}

# -- Print script result
$res = 'SUCCESS: All services, processes and counters successfully checked'
echo $res
exit


#################################################################################
# // --- Catch script exceptions ---
#################################################################################

trap [Exception]
{
  $res = 'UNCERTAIN: ' + $_.Exception.Message
  echo $res
  exit
}