Wednesday, September 23, 2009

Script to check if a service exist on multiple servers

We had a requirement where we had to check if a particular service is present on multiple servers using vbscript
******************************
Const ForReading = 1
Const SUCCESS = 0
stringInputFile = "C:\input.txt"
strService = "clipsrv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objectTextStream = objFSO.OpenTextFile(stringInputFile, ForReading)
arrServers = Split(objectTextStream.ReadAll, vbCrLf)
objectTextStream.Close
Set objShell = CreateObject("WScript.Shell")
On Error Resume Next
For Each strServer in arrServers
Set objScriptExec = objShell.Exec("ping -n 2 -w 1000 " & strServer)
strPingResults = LCase(objScriptExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
Set objWMIService = GetObject("winmgmts:\\" & strServer)
If Err.Number <> 0 Then
WScript.Echo "FAILURE: " & strServer & " [WMI connection failed]"
Err.Clear
Else
Set objService = objWMIService.Get("Win32_Service.Name='" & strService & "'")
If Err.Number Then
WScript.Echo strServer & " FAILURE: " & strService & " [Service not found]" Err.Clear
Else
WScript.Echo strServer & " SUCCESS: " & strService & " [Service found]"
End If
End If
Else
WScript.Echo "FAILURE: " & strServer & " [ping failed]"
End If
Next
********************************************

Tuesday, September 1, 2009

Schedule+ Free/Busy system folder is missing

http://support.microsoft.com/default.aspx?scid=kb;en-us;284200&Product=exch2k

Script to monitor service status

We had a requirement to monitor a service status on multiple servers and send a mail to the team when the service is no longer is available /stopped.
This script is used to monitor a particular service and uses the SMTP server to send a mail to the team using the CDO object method.
===============================
'variable declaration
dim objShell, objNetdim strToEmailAddress, strFromEmailAddress, strServiceNameToCheckdim strSMTPServer, strSMTPServerPortdim strComputerName
Set objNet = CreateObject("WScript.NetWork")
' **** Set Variables here *****
strComputerName = "server name that you need to monitor"
strToEmailAddress = "email address"
strFromEmailAddress = "email address"
strServiceNameToCheck = "service display name to monitor "
strSMTPServer = "smtp server ip address or FQDN "
strSMTPServerPort = "25"
strsub = "service status"
set objShell = CreateObject("Shell.Application")
If objShell.IsServiceRunning(strServiceNameToCheck) Then
Wscript.Quit
else
Set objMessage = CreateObject("CDO.Message")
'Send Message
objMessage.From = strFromEmailAddress
objMessage.To = strToEmailAddress
objMessage.Subject = strsub
objMessage.TextBody = "The Service '" & strServiceNameToCheck & "' stopped on " & strComputerName & " Server " & vbcrlf & "Time: " & Now
objMessage.Configuration.Fields.Item http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPserverobjMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = strSMTPServerPortobjMessage.Configuration.Fields.UpdateobjMessage.Send
End If
set objShell = nothing
set objNet = Nothing
=======================
This can be set as a scheduled task to monitor daily or depending on the schedule when required.

Service Tag - Script

May I have your service tag number please :-)
on error resume next
strComputer=InputBox ("Enter the computer name of the server you'd like to query for Service Tag")
Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
For each objitem in colitems
if objitem.serialnumber ="" Then Msgbox "No tag was available!"
Else
Wscript.echo "Dell Service Tag: " & objitem.serialnumber
End If
Next