A.3 Restore Script

Use the Restore feature to restore GPO settings, Active Directory links, and security settings individually or all together.

Restoring a GPO does not require that another GPO be present in the Active Directory environment.

To write a Visual Basic script or method for restoring backed up policies:

  1. In Notepad, create the following Visual Basic script:

    dim x, a
    set x = CreateObject("GPExplorer.PolicyManager.1")
    REM ***** RestorePolicy(NULL, Backup folder path, Domain Name, DC Name, option)
    x.RestorePolicy NULL, "BackupFolder\{BackupGUID}", "Domain","DomainController", Option
    set x = nothing

    or

    Create the following C# method:

    public static void Restore()
            {
                string sPath = "BackupFolder/{BackupGUID}";
                string sDomainController = "DomainController";
                string sDomain = "Domain";
                long sReserved = 0;
                IfaExplorerRoot oEXPRroot = new PolicyManager();
                oEXPRroot.RestorePolicy(null, sPath, sDomain, sDomainController, sReserved);
                Console.WriteLine("GPO restored successfully");
                Console.ReadKey();
            }
  2. Modify the variables as follows:

    BackupFolder

    Type the path and the name of the backup folder from which you are going to restore the GPO.

    BackupGUID

    Type the GUID number that corresponds to the GPO you want to restore.

    Domain

    Type the name of the domain to which you want to restore the GPO.

    DomainController

    Type the name of the primary domain controller of the domain. Provide the full computer name, which has the actual computer name along with the domain to which it belongs. You can find the full name on the Network Identification tab of the Property page of My Computer.

    Reserved

    Specify 0.

  3. When you are finished, your script should look similar to the following example:

    REM **** Restore **********************************************
    dim x , a
    set x = CreateObject("GPExplorer.PolicyManager.1")
    REM ***** RestorePolicy(NULL, Backup folder path, Domain Name, DC Name, option)
    x.RestorePolicy NULL, "E:\GPO Backups\Backup
    Scripts\Backups\{33A49A2C-6A2A-45D1-B7CE-A8AEC3A3C325}",
    "child-domain.com", "develchild.child-domain.com", 0
    set x = nothing
    Wscript.Echo "Restore Completed"
    REM ***********************************************************

    or

    Your C# method should look similar to the following example:

    public static void Restore()
            {
                string sPath = "C://Folder/{AA968F38-B89D-4688-B766-4B7A4D5CD5C2}/";
                string sDomainController = "MYDOMAINCONTROLLER.MYDOMAIN.LAB";
                string sDomain = "MYDOMAIN.LAB";
                long sReserved = 0;
                IfaExplorerRoot oEXPRroot = new PolicyManager();
                oEXPRroot.RestorePolicy(null, sPath, sDomain, sDomainController, sReserved);
                Console.WriteLine("GPO restored successfully");
                Console.ReadKey();
            }
  4. To restore multiple GPOs, copy the x.RestorePolicy line, for Visual Basic scripts, or the sPath line, for C# methods, as many times as necessary, modifying only the BackupGUID section.

  5. Save the file with any suitable name, and an extension of .vbs for Visual Basic scripts, to the location of your choice (for example, importGPOs.vbs), or compile the solution, then execute the executable build.