Get the App
SLTechnology News&Howtos  ›  Servers  › 

Powershell script cooperates with task scheduler to realize automatic backup of group policy

Shulou Source: shulou.com Published: 2022-06-02 12:15:10 10月01日 Update

Also today, I encountered a problem requiring automatic backup of Group Policy (GPO) every five minutes. I racked my brains to find that the graphical interface could not solve this problem, so I began to wonder if Powershell could solve it, and finally I really solved it. Here's what I did.

First put the script:

Explain:

Import the grouppolicy module and use its method later

Define a time variable in which daily backups are recorded in a folder named after the date

Specify a new folder in a directory under disk C.

Then specify to back up all group policies to this folder

Save and run:

Successful backup, happy

And then there's the big story:

Open the Task Scheduler and click create Task (note that you create a task instead of a basic task)

Naturally, the name goes without saying.

Create a new trigger according to your own needs

Click the action again (here you need to pay attention to "ω" =)

The program should choose Powershell instead of script, because the default execution of ps1 script is to edit rather than run

Parameter. That's the script path.

Start with the folder where the script is written

Then the rest depends on the configuration you need.

Complete

The automatic backup will begin in five minutes, and then we'll try to restore it.

Right-click in Group Policy Management to select Group Policy object to manage backup

Then select your backup directory

This is the strategy for all backups. Watch the timestamp for on-demand recovery.

Xiaobai opens a blog. Comments are welcome.

Tags: Backup policy script task file folder selection program time directory management run success rack your brains and then no needless to say parameters variables names Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology Microsoft Docker macOS