Submitted By: Jeremy Lawrence

Automates a system state backup of a desktop/server and prompts you as to where you would like the backup file stored. I utilize this script in my server environment for DR purposes.

Visual Basic
Edit|Remove
===========================================================================
' Name: SystemStateBackup.vbs
' Version: 2.0
' Author: Jeremy Lawrence
' Bug Reports & Enhancement Req: jlawrence@giveblood.org
'
' Main Function:	Performs a System State Backup on WinXP, Win2K, and Win2k3
'===========================================================================
DIM strDate
DIM strComputerName
DIM strBytes

Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputerName = WshNetwork.ComputerName
strDate = month(Now) & "-" & day(Now) & "-" & year(Now)
Const HARD_DISK = 3


strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_LogicalDisk WHERE DriveType = " _
        & HARD_DISK & "")
For Each objDisk in colDisks
    strBytes = FormatNumber((objDisk.FreeSpace / 1073741824),2)
    If strBytes <= 0.30 then
    Wscript.Echo "You do not have enough disk space to place the System State backup on this drive.  Please find another location."
 Else
    Wscript.Echo objDisk.DeviceID & " has " & " " & strBytes & "GB of space available"
End If

Next

Set oWshShell = CreateObject("WScript.Shell")

 

strDest=inputbox("Please enter the location you would like to save the system state.  The location must have a minimum 300MB of space." & vbCr & vbCr & "Example:  C:\Systemstate","CSC System State Backup","C:\systemstate")

 

oWshShell.Run "ntbackup backup systemstate /f " & strDest & "\Systemstate" & "_" & strDate & "_" & strComputerName & ".bkf /m copy"