Restore_GPO.hta (In the book)

Download file: restore_gpo.hta (4 Kb)

<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>Restore GPO</TITLE>
<HTA:APPLICATION ID="RestoreGPO"
APPLICATIONNAME="RestoreGPO"
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">
Dim gpmBackup_List, gpmBackupDir

Sub Window_OnLoad
self.resizeTo 800,500
BackupFolder.Value = GetDefaultFolder(UseDate)
CreateGPMObjects
End Sub

Sub GetBackupFolder
BackupFolder.Value = BrowseForFolder
End Sub

Sub GetBackupList
Dim BackupList_HTML
Dim gpmSearchCriteria
set gpmSearchCriteria = gpm.CreateSearchCriteria()
gpmSearchCriteria.Add _
gpmConstants.SearchPropertyBackupMostRecent, gpmConstants.SearchOPEquals, True

Set gpmBackupDir = gpm.GetBackupDir(BackupFolder.Value)
Set gpmBackup_List = gpmBackupDir.SearchBackups(gpmSearchCriteria)

For i=1 To gpmBackup_List.Count
With gpmBackup_List.Item(i)
AddHTML BackupList_HTML, "<li>" & .GPODisplayName & _
": " & "Backed up on " & .Timestamp & " (" & .Comment & ")"
End With
Next
BackupList_Span.innerHTML = BackupList_HTML
SelectBackup_Div.style.display = "block"
End Sub

Sub RestoreGPO
Dim GPONumber
If IsNumeric(GPOToRestore.Value) Then
GPONumber = CInt(GPOToRestore.Value)
If GPONumber > 0 And GPONumber <= gpmBackup_List.Count Then
StartRestore GPONumber
Else
MsgBox "Invalid GPO number, please try again", vbOKOnly+vbExclamation, "Error"
GPOToRestore.Value = ""
End If
Else
MsgBox "Invalid GPO number, please try again", vbOKOnly+vbExclamation, "Error"
GPOToRestore.Value = ""
End If
End Sub

Sub StartRestore(GPONumber)
Dim gpmRestoreGPO
Set gpmRestoreGPO = gpmBackupDir.GetBackup(gpmBackup_List.Item(GPONumber).ID)

Dim MsgText
With gpmRestoreGPO
MsgText = "About to restore the following GPO:" & VbCrLf & VbCrLf & _
"GPO FriendlyName: " & .GPODisplayName & VbCrLf & _
"Domain: " & .GPODomain & VbCrLf & _
"Comment: " & .Comment & VbCrLf & _
"GPO GUID: " & .GPOID & VbCrLf & _
"GPO Backup GUID: " & .ID & VbCrLf & _
"Backup Timestamp: " & .Timestamp & VbCrLf & VbCrLf & _
"Are you sure?"
End With

If MsgBox(MsgText,vbYesNo+vbQuestion,"Are you sure?") = vbYes Then
Dim gpmResult, gpmResult_Status
Set gpmResult = gpmDomain.RestoreGPO(gpmRestoreGPO,0)
Set gpmResult_Status = gpmResult.Status
If gpmResult_Status.Count <> 0 Then
MsgText = ""
For i = 1 To gpmResult_Status.Count
MsgText = MsgText & gpmResult_Status.Item(i).Message & vbCrLf
Next
MsgBox MsgText, vbOKOnly + vbExclamation, "Errors occurred."
Else
MsgBox "GPO successfully restored!",vbOKOnly + vbExclamation,"Success"
End If
End If
End Sub
</SCRIPT>
<div class="Title">Restore GPO</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="GetListButton" onclick="GetBackupList()">Get GPO List</button></td>
</tr>

</table>
<div id="SelectBackup_Div" style="display:none">
<table>
<tr>
<td>Enter GPO Number to Restore</td>
<td align="left"><input type="text" size="2" id="GPOToRestore"></td>
<td><button id="RestoreGPOButton" onclick="RestoreGPO()">Restore GPO</button></td>
</tr>
</table>
</div>
<p>
<ol>
<span id="BackupList_Span"></span>
</ol>


</BODY>
</HTML>
 

Be a hero! Report a problem with this web page here

Event Calendar

Find out where and when Jeremy will be speaking next.

November 2008
SMTWTFS
1
2345678
9101112131415
16171819202122
23242526272829
30
Mon, Nov 10 - Thu, Nov 13
Windows Connections -- Vegas
It's WinConnections time! All sorts of great speeches this time. GP Troubleshooting, My Pre-Con, App-V 101. Will you be there?
www.winconnections.com
Mon, Nov 17 - Tue, Nov 18
Two-Day Intensive Group Policy Essentials Workshop (taught by Jeremy Moskowitz (Lead Instructor) - GPanswers.com / Moskowitz, Inc. )
 Final class of 2008.
This is a Two-Day Intensive Group Policy Essentials Workshop in Atlanta, GA !
Wed, Nov 19 - Thu, Nov 20
Two-Day "Group Policy 2.0" Catch-Up Workshop (taught by Jeremy Moskowitz (Lead Instructor) - GPanswers.com / Moskowitz, Inc. )
 Final class of 2008.
This is a Two-Day "Group Policy 2.0" Catch-Up Workshop in Atlanta, GA !
Fri, Nov 21 - Fri, Nov 21
One-Day Advanced Group Policy Workshop (XP/Vista Focused) (taught by Jeremy Moskowitz (Lead Instructor) - GPanswers.com / Moskowitz, Inc. )
 Final class of 2008.
This is a One-Day Advanced Group Policy Workshop (XP/Vista Focused) in Atlanta, GA !