Restore_GPO.wsf (In the book)

Download file: restore_gpo.wsf (3 Kb)

<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>
<runtime>
<description>Restore backed up GPOs.</description>
<named name="Folder"
helpstring="Folder containing the backed up GPOs"
type="string" required="true" />
<named name="GPO"
helpstring="Name of GPO to restore."
type="string" required="true" />
<named name="List"
helpstring="List the GPOs in the backup folder."
type="simple" required="false" />
</runtime>
<script language="VBScript" src="/GPMgmt.vbs" />
<script>
CheckCScript
CreateGPMObjects
Dim BackupFolder, GPO, gpmBackupDir
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
MsgBox "Missing /Folder: argument"
WScript.Quit
End If
If WSH.Arguments.Named.Exists("LIST") Then
ListGPOs
WScript.Quit
End If
If WSH.Arguments.Named.Exists("GPO") Then
GPOToRestore = WSH.Arguments.Named("GPO")
Else
MsgBox "Missing /GPO: argument"
WScript.Quit
End If
End If

If Not(FolderExists(BackupFolder)) Then
WScript.Echo BackupFolder & " does not exist."
WScript.Quit
End If

Set gpmBackup_List = GetGPOBackups(BackupFolder)

'WScript.Echo "Current GPO backups in " & BackupFolder
Set gpmRestoreGPO = Nothing
For i=1 To gpmBackup_List.Count
With gpmBackup_List.Item(i)
If .GPODisplayName = GPOToRestore Then
Set gpmRestoreGPO = gpmBackupDir.GetBackup(.ID)
With gpmRestoreGPO
WScript.Echo "GPO Friendly Name: " & .GPODisplayName
WScript.Echo "Domain: " & .GPODomain
WScript.Echo "Comment: " & .Comment
WScript.Echo "GPO GUID: " & .GPOID
WScript.Echo "GPO Backup GUID: " & .ID
WScript.Echo "Backup Timestamp: " & .Timestamp
WScript.Echo vbNL
End With
Exit For
End If
End With
Next

If gpmRestoreGPO Is Nothing Then
WScript.Echo "Could not find specified GPO!"
WScript.Quit
End If

WScript.StdOut.Write "Are you sure you want to restore this GPO? (y or n) "
rs = WScript.StdIn.ReadLine
WScript.Echo VbCrLf

If StrComp(rs,"y",vbTextCompare) = 0 Then
WScript.Echo "Restoring selected GPO..."
Set gpmResult = gpmDomain.RestoreGPO(gpmRestoreGPO,0)
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
Next
gpmResult.OverallStatus()
Else
WScript.Echo "Successfully restored GPO. This did not restore links from containers."
End If
Else
WScript.Echo "Operation aborted. No GPOs restored."
End If

Sub ListGPOs
Set gpmBackup_List = GetGPOBackups(BackupFolder)
WScript.Echo "Here is a list of the most current GPO backups:"
For i=1 To gpmBackup_List.Count
With gpmBackup_List.Item(i)
WScript.Echo .GPODisplayName & ": " _
& "Backed up on " & .Timestamp _
& " (" & .Comment & ")"
End With
Next
End Sub
</script>
</job>
 

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 !