PoshCode Archive  Artifact [bec40949d3]

Artifact bec40949d3ed0770fa7ffe9bad9dd4c87b17d9fb0dff6f5105cdbb4595f0cc1d:

  • File Check-Service-on-Servers.ps1 — part of check-in [e4a4d60412] at 2018-06-10 13:31:20 on branch trunk — If you download or use, please tweet it or email me. Thanks! (user: Matt Schmitt size: 2455)

# encoding: ascii
# api: powershell
# title: Check Service on Servers
# description: If you download or use, please tweet it or email me.  Thanks!
# version: 1.0
# type: script
# author: Matt Schmitt
# license: CC0
# x-poshcode-id: 3803
# x-archived: 2013-11-11T19:09:27
# x-published: 2013-11-29T12:46:00
#
# This project is in response to “script to monitor a service on a server” script request:  http://gallery.technet.microsoft.com/scriptcenter/site/requests/script-to-monitor-a-service-on-a-server-636b6a0d?ShowSubmitLinkForm=False
# This script checks the status for a defiled service for a group of servers, listed in the serverList.txt file.  In this case the CPSVS service.  However this can be changed to the name of the service you want to check.  It exports the status of the service for each server.  After that, it sends the output file as an attachment in an email to a defined group of addresses.
# To use this script your will need to make some changes in the scritp:
# Create Server list and save to serverList.txt file
# Adjust the import location of the serverList.txt file on Line 15 
# Change the service – to the service you want to check
# Adjust the output location of the ServerServiceStatus.csv file on line 27
# Adjust the email address on Line 32.
# To use more than one email address, separtate with a comma:
# recipient1@domain.com, recipient2@domain.com
# Adjust the SmtpServer address on Line 32
# # I hope you find this useful!  Comments and suggestions are welcome!
# Matt
#
<#
  Author:   Matt Schmitt
  Date:     11/29/12 
  Version:  1.0 
  From:     USA 
  Email:    ithink2020@gmail.com 
  Website:  http://about.me/schmittmatt
  Twitter:  @MatthewASchmitt
  
  Description
  A script for checking the status of a service on a group of servers, from a list in a file.  
#>


$serverList = Import-Csv 'c:\serverList.csv'

"Server" +"`t" + "Status" | Out-File c:\ServerService.csv


foreach ($element in $serverList) 
{
    
    $sStatus = get-service -Name "CPSVS" | Select-Object -expand Status

    $server = $element | Select-Object -expand Server

    $server + "`t" + $sStatus | Out-File -append c:\ServerServiceStatus.csv

} 


Send-MailMessage -From donotreply@test.com -To recipient@domain.com -subject "Spooler Service Report" -Body "Attached is Server Service report." -Attachments "c:\ServerServiceStatus.csv" -SmtpServer "xxx.xxx.xxx.xxx"