Backup_All_GPOs.hta (In the book)

Jan
25
2013

 

<HTML>
<HEAD>
<!--
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!
-->
<TITLE>Backup All GPOs</TITLE>
  <HTA:APPLICATION ID="Backup_All_GPOs" 
    APPLICATIONNAME="Backup_All_GPOs" 
    BORDER="dialog"
    CAPTION="yes"
	CONTEXTMENU="yes"
    ICON="graphics/title.ico"
    INNERBORDER="yes"
    MINIMIZEBUTTON="yes"
    MAXIMIZEBUTTON="yes"
    SCROLLABLE="yes"
    SHOWINTASKBAR="yes"
    SINGLEINSTANCE="yes"
    SYSMENU="yes"
    WINDOWSTATE="maximize">
  <LINK href="GroupPolicy.css" rel="stylesheet" type="text/css">
  <SCRIPT src="GPMgmt.vbs" language="VBScript"></SCRIPT>
  <SCRIPT src="HTA_Help.vbs" language="VBScript"></SCRIPT>
</HEAD>
<BODY>
<SCRIPT language="VBScript">
Sub Window_OnLoad
self.resizeTo 800,400
CreateGPMObjects
BackupFolder.Value = GetDefaultFolder(UseDate)
End Sub

Sub GetBackupFolder
BackupFolder.Value = BrowseForFolder
End Sub

Sub StartBackup
self.resizeTo 100,0
BackupFolder.Disabled = True
BrowseButton.Disabled = True
StartBackupButton.Disabled = True
BackupGPOs
self.resizeTo 800,400
BackupFolder.Disabled = False
BrowseButton.Disabled = False
StartBackupButton.Disabled = False
End Sub

Sub BackupGPOs
Dim Results_HTML
Dim FSO, GPOBackupFolder
AddHTML Results_HTML, "Results:<br>"
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(BackupFolder.Value) Then
	Set GPOBackupFolder = FSO.GetFolder(BackupFolder.Value)
Else
	Set GPOBackupFolder = FSO.CreateFolder(BackupFolder.Value)
	AddHTML Results_HTML, "<li>Created folder " & BackupFolder.Value
End If

Set Network = CreateObject("WScript.Network")

set gpmSearchCriteria = gpm.CreateSearchCriteria()
Set GPO_List = gpmDomain.SearchGPOs(gpmSearchCriteria)

For Each GPO In GPO_List
	AddHTML Results_HTML, "<li>Backing up the " & GPO.DisplayName & " GPO...."
	Results_Span.innerHTML = Results_HTML
	AddHTML Results_HTML, "<ul>"
	Set gpmResult = GPO.Backup(GPOBackupFolder.Path,"Backup performed by " & Network.UserName)
	Set gpmResult_Status = gpmResult.Status
	If gpmResult_Status.Count <> 0 Then
		AddHTML Results_HTML,"<ul>"
		For i=1 To gpmResult_Status.Count
			AddHTML Results_HTML, "<li>" & gpmResult_Status.Item(i).Message
		Next
		AddHTML Results_HTML,"</ul>"
		gpmResult.OverallStatus()
	Else
		AddHTML Results_HTML, "<li>GPO Backup successful."
	End If
	AddHTML Results_HTML, "</ul>"
	Results_Span.innerHTML = Results_HTML
Next

AddHTML Results_HTML, "<li>Completed GPO backups."
Results_Span.innerHTML = Results_HTML
End Sub

</SCRIPT>
<div>Backup All GPOs</div>
<p>
<table border="0">
	<tr>
		<td>Backup Location</td>
		<td colspan="2"><input type="text" size="75" id="BackupFolder"></td>
	</tr>
	<tr>
		<td></td>
		<td align="left"><button id="BrowseButton" onclick="GetBackupFolder()">Change Location</button></td>
		<td align="right"><button id="StartBackupButton" onclick="StartBackup()">StartBackup</button></td>
	</tr>
</table>
<p>
<ul>
	<span id="Results_Span"></span>
</ul>
</BODY>
</HTML>
Copyright © GPanswers.com. All rights reserved. GPanswers.com is a service of PolicyPak Software