Enumerating the If... Then: Scripts

Tuesday, April 29, 2008

Symantec: Send an Email alert when Backup Exec System Recovery backup job fails

Tested.
In use at work.


Set this script to activate after your backup job completes.


Set objShell = CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile_
("c:\documents and settings\all users\application data\symantec\backup exec system recovery\logs\backup exec system recovery.log.txt", 1, 0, -2)


strSearchString = "High Priority"


i = 0

do while not objFile.atendofstream
redim preserve strLines(i)
strLines(i) = objFile.readline
i = i + 1
loop

objFile.close

strLastLine = strLines(i-1)


if instr(strLastLine,strSearchString) <> 0 then

strEmailBody = mid(strLastLine, instr(strLastLine,strSearchString),_
len(strLastLine) - instr(strLastLine,strSearchString) + 1)


'''' Sends Email
Set objMessage = CreateObject("CDO.Message")

objMessage.Subject = "[ " &

objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & " ] reporting a System

Recovery job error"
objMessage.From = "ImaFromAddr"
objMessage.To = "ImaToAddr"
objMessage.TextBody = strEmailBody

objMessage.Configuration.Fields.Item_
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item_
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ImaSMTPSrv"
objMessage.Configuration.Fields.Item_
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update

objMessage.Send

else

' didn't find strSearchString in the last line of the file
wscript.echo "no string in string"

end if

Friday, April 18, 2008

RealQuickScripts: Getting or Setting Computer Description

Tested.
In use at work.



Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = WScript.Arguments.Item(0)

Set objRegistry = GetObject ("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "System\CurrentControlSet\Services\lanmanserver\parameters"
strValueName = "srvcomment"


if WScript.Arguments.Count = 1 then 'display current description

wscript.echo GetValue()

else

wscript.echo "Description of " & WScript.Arguments.Item(0) & " has been set to " & vbnewline & vbnewline & " " & SetValue(WScript.Arguments.Item(1))

end if

wscript.quit

function GetValue()

objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strDescription
GetValue = strDescription

end function

function SetValue(strDescription)

objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strDescription
SetValue = strDescription

end function


source