Backup_All_GPOs.wsf (In the book)

Jan
24
2013

 

<job>
<comment>
Script : List_GPMC_Information.wsf
From the book "Group Policy" by Jeremy Moskowitz

The contents of this script are provided "as is".  
No warranty of any kind, either express or implied, is made in relation 
to the availability, accuracy, reliability or content of this script.
ALWAYS test scripts before using in your production network!
</comment>
<script language="VBScript" src="GPMgmt.vbs" />
<script>
CheckCScript
CreateGPMObjects
If WSH.Arguments.Count > 0 Then
    If WSH.Arguments.Named.Exists("Folder") Then
        BackupFolder = WSH.Arguments.Named("Folder")
        If Not(Right(ReportFolder,1) = "\") Then
            BackupFolder = BackupFolder & "\"
        End If
    Else
        BackupFolder = WScript.Path
    End If
    If WSH.Arguments.Named.Exists("UseDate") Then
        BackupFolder = BackupFolder & GetDateName & "\"
    End If
Else
    WScript.Echo "Missing arguments"
End If

Set FSO = CreateObject("Scripting.FileSystemObject")
If Not(FSO.FolderExists(BackupFolder)) Then
    WScript.Echo "Creating folder " & BackupFolder
    FSO.CreateFolder BackupFolder
End If

Set Network = CreateObject("WScript.Network")

set gpmSearchCriteria = gpm.CreateSearchCriteria()
Set GPO_List = gpmDomain.SearchGPOs(gpmSearchCriteria)
Set LogFile = FSO.CreateTextFile(BackupFolder & "BackupLog.txt")
LogFile.WriteLine "Backup performed by " & Network.UserName & vbNL
For Each GPO In GPO_List
	WScript.Echo "Backing up the " & GPO.DisplayName & " GPO."
	LogFile.WriteLine "Backing up the " & GPO.DisplayName & " GPO."
	Set gpmResult = GPO.Backup(BackupFolder,"Backup performed by " & Network.UserName)
	Set gpmResult_Status = gpmResult.Status
	If gpmResult_Status.Count <> 0 Then
		For i=1 To gpmResult_Status.Count
			WScript.Echo gpmResult_Status.Item(i).Message
			LogFile.WriteLine gpmResult_Status.Item(i).Message
		Next
		gpmResult.OverallStatus()
	Else
		WScript.Echo "GPO Backup successful."
		LogFile.WriteLine "GPO Backup successful." & vbNL
	End If
Next
LogFile.Close
WScript.Echo "Completed GPO backups."

</script>
</job>