lunes, 15 de diciembre de 2014

Checking with Powershell if Citrix XenApp 7.6 Services are running

Hi Citrix guys.

This time only I have a simple script to check if all citrix services are runing.
If some service is Stopped, restart again and send an email to report.

Das ist nicht Cool

<# =======================================================================

File Name: CheckCitrixMonitoring_v01.ps1

Author: citrixpedia@gmail.com

Comments: Script developed to check citrix monitoring services. if the services is stopped, it will be started and it will send an email.


======================================================================= #>


$LogFileName="$env:TEMP\CheckCitrixMonitoring.log"

$smtpServer="<smtp_server_fqdn>"
$smtpFrom="<sender_address>"
$smtpAddress="<recipiente_address>"

$eventSource="Citrix Monitoring"

$eventID=7601

#-------------------------------------

# create body message
#-------------------------------------

$header = "The following services were stopped and it has proceeded to start them again.`nPlease, check them: "

$footer= "Please, notify to: $smtpAddress about this message."

#------------------------------

# write event in the system
#------------------------------

New-EventLog -LogName System -Source $eventSource


#-------------------------------------

# Check Citrix Services and if the service is stopped, restart again and send mail to report
#-------------------------------------


$stoppedServices=Get-Service | Where-Object {$_.DisplayName -like "*Citrix*"} | Where-Object {$_.Status -eq "Stopped"} | fl display*,status

$stoppedServices | Out-File -Encoding ASCII $LogFileName

if ($stoppedServices) {

    $readFile=Get-Content -Encoding ASCII $LogFileName
    Get-Service | Where-Object {$_.DisplayName -like "*Citrix*"} | Where-Object {$_.Status -eq "Stopped"}| Start-Service
    Write-EventLog -LogName System -Source $eventSource -EventId $eventID "Warning" –Message "`n$header`n`n$readFile`n`n$footer"

    Send-mailmessage -SmtpServer $smtpServer -from $smtpFrom -to $smtpAddress1 -Subject "Citrix Monitoring Alert -> $env:COMPUTERNAME" -body "`n$header`n`n$readFile`n`n" -Attachments $LogFileName


}




No hay comentarios:

Publicar un comentario