Click here to Skip to main content
15,917,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to write a script for creating a windows image backup and naming it and moving it to the network location and sending the mail system admin

Batch File to initiate the System VM script

"@echo off
start D:\ADBackup\ADBackup.vbs
ECHO <servername> (IP address) ADBACKUP COMPLETED SUCCESSFULLY. > D:\ADBackup\EVENTS.TXT
ECHO Folder Path is "\\(network path)\%date:~7,2%.%date:~4,2%.%date:~10,4%" >> D:\ADBackup\EVENTS.TXT
ECHO The File Name is dss4dc01_ADBackup.bkf >> D:\ADBackup\EVENTS.TXT
MD "\\network path\%date:~7,2%.%date:~4,2%.%date:~10,4%"
C:\WINDOWS\system32\wbadmin.exe backup "@D:\ADBackup\ADBackup.bks" /n "ADBackup.bkf created on %%date%% at %%time%%" /d "ADBackup Set created %date% at %time%" /v:no /r:no /rs:no /hc:off /m normal /j "Active Directory Backup" /l:s /f "D:\ADBackup\ASTMUMDC001_ADBackup.bkf"
copy D:\ADBackup\(servername).bkf "networkpath\%date:~7,2%.%date:~4,2%.%date:~10,4%"
tskill wscript"

VB script for DC backup

VB
On Error Resume Next
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
'Open the file for reading
Set f = fso.OpenTextFile("D:\ADBackup\Events.txt", ForReading)
'The ReadAll method reads the entire file into the variable BodyText
BodyText = f.ReadAll
'Close the file
f.Close
Set f = Nothing
Set fso = Nothing

For Each strComputer In aryTasks

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate, (Security)}!\\" & _
strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("Select * from __instancecreationevent where " _
& "TargetInstance isa 'Win32_NTLogEvent' " _
& "and TargetInstance.EventCode = '8001' ")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
strAlertToSend = objLatestEvent.TargetInstance.User _
& "ALERT!!! Event 1002 Siebel Application Crash file has been generated."
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "<From address>"
objEmail.To = "<Receipient address>"
objEmail.Subject = "ADBackup: Server name  (IP address) Active Directory Backup completed Successfully."
objEmail.AddAttachment "D:\ADBackup\Events.txt"
objEmail.Textbody = BodyText
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"10.66.11.50"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
Loop
Next



the folder is created and mail is generated and backup is not initiating
can any one find out the mistake and correct me with the script

Thanks
Gowsic
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900