# Change Log
# NTG 1/28/2010 Adjusted to send email to XXXXXXXXXXXXXXXX
# th 2/1/2010 = no change here but added eurestis@microsoft.com to sp_emailb in MSDB \\bakerx as
# copy recipent
#######################################################
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
cls
$mydate = Get-Date
Write-Host "The Date is $mydate"
sleep 2
Write-Host "#####################################" -foregroundcolor red -backgroundcolor green
Write-Host "# #"-foregroundcolor red -backgroundcolor blue
Write-Host "# Real-Time Services Analyzer #"-foregroundcolor red -backgroundcolor black
Write-Host "# By: Nigel Glenwood #"-foregroundcolor red -backgroundcolor blue
Write-Host "#####################################"-foregroundcolor red -backgroundcolor green
# Write-Host "Name, ID, FS, FreeSpace, Size, Usedspace"-foregroundcolor white -backgroundcolor blue
# Nigel Notes
write Services Status > smnigel4.html
#
# first get-content grabs the filenames that contains the servers for each space
# Then for each space, run through that file name and grab all the servers and send alerts as needed.
# So basically, these are kind of loops inside of loops.
# -Nigel
# beginning of outmost loop
#get-content d:\mumar\thefilenames.txt | Foreach-Object {
#write-host $_ is the value I just read let me throw that into a variable for me
#$filetoprocess=$_
#write-host $filetoprocess is the file I am going to process now
# above works like . does not work
#Invoke-Expression -ComputerName aitpsql511 -Command 'get-service'
#$svc={Param ([string]$computer=$env:computername,
# [string]$name="*")
# [system.serviceprocess.servicecontroller]::GetServices($computer) |
# where {$_.name -like $name}
# }
# now run it
#&$svc "aitpsql511"
# above works like sh*t.. does not work
get-content web1servers.txt | ForEach-Object {
$servername=$_
# get-wmiobject win32_service -computer $servername | Select *
get-wmiobject win32_service -filter "StartMode like '%Auto%' and Name like '%ProcurementServiceHost%' " -computer $servername | Select Name, State, Startmode | ForEach-Object {
write-host Server Name $Servername
write-host The NAME of Service is $_.Name
write-host The State of Service is $_.State
write-host The Startup Type of Service is $_.StartMode
if ($_.State -eq 'Stopped')
{ sqlcmd /S bakerx /E -d msdb /Q "exec sp_emailb 'Server: $servername Critical Service Has Gone into a Stopped State, $_.Name ','CFINOPS', '$servername'"
write-host $_.Name $_.State, $Servername is in a BAD State -backgroundcolor red
write $_.Name $_.State, $Servername is in a BAD State >> smnigel4.html
}
else
{
write-host $_.Name $_.State, $Servername is in a Running State -backgroundcolor green
write $_.Name $_.State, $Servername is in a RUNNING State >> smnigel4.html
}
}
$monitored='ProcurementServicesHost'
get-content web1services.txt | ForEach-Object {
$servicename=$_
write-host I have just read the value for service name as $servicename, checking on that service now
# get-wmiobject win32_service -computer $servername | Select *
# -filter "Name='Revelation LSS Provider' "a
# -filter "Name like '%LSR%'"
get-wmiobject win32_service -filter "Name like '%$servicename%'" -computer $servername | Select Name, State, Startmode | ForEach-Object {
write-host Server Name $Servername
write-host The NAME of Service is $_.Name
write-host The State of Service is $_.State
write-host The Startup Type of Service is $_.StartMode
$monitored=$monitored+$_.name+$_.State
if ($_.State -eq 'Stopped')
{ sqlcmd /S bakerx /E -d msdb /Q "exec sp_emailb 'Server: $servername Critical Service Has Gone into a Stopped State, $_.Name ','CFINOPS', '$servername'"
write $_.Name $_.State, $Servername is in a STOPPED State >> smnigel4.html
}
else
{
write-host $_.Name $_.State, $Servername is in a Running State -backgroundcolor green
write $_.Name $_.State, $Servername is in a RUNNING State >> smnigel4.html
write-host got to here dude
}
}
}
}
$the_date=get-date
write-host Completed at: $the_date >> smnigel4.html
sleep 5
# beginner of inner loop
#get-wmiobject win32_logicaldisk -filter "drivetype=3" -computer (get-content $filetoprocess'.txt') | Select #SystemName,DeviceID,FileSystem,@{Name="Freespace";Expression={([Math]::round([long]$_.FreeSpace/1gb,0))}},@{Name="FreespaceM#e#gs";Expression={([Math]::round([long]$_.FreeSpace/1mb,0))}},@{Name="Size";Expression={([Math]::round([long]$_.Size/1gb,0))}}#,#@{Name="Usedspace";Expression={([Math]::round([long]$_.Size/1gb-[long]$_.FreeSpace/1gb,0))}} | ForEach-Object {
# -filter "StartupType like '%Auto%'"
# This will send an email to Nigel that it ran, so every 5 minutes, can be used to troubleshoot
# or to ensure it is running correctly through scheduler
# sqlcmd /S bakerx /E -d msdb /Q "exec sp_emailc 'Server: $servername The csprob1 Services Check ran State, $_.Name $monitored','dddlen', '$servername'"
# sqlcmd /S bakerx /E -d msdb /Q "exec sp_emailc 'Server: $servername The SERVER Services Check ran State, $_.Name $monitored ','mddddddn', '$servername'"
No comments:
Post a Comment