Hi,
This script will automatically backup all GPO in your AD environment, also it will check for errors and mail you about them (with the log file).
First install GPMC.
My sample is using the following:
- 7Zip exe
- Mailit exe
- d:\work\gpo (where the scripts are)
- d:\backup\gpo (where the backup is)
the script:
==================================================
rd D:\Work\GPO_Backup\Temp /s /q
md D:\Work\GPO_Backup\Temp
cscript "C:\Program Files\GPMC\Scripts\BackupAllGPOs.wsf" D:\Work\GPO_Backup\Temp > log.txt
find /i "Backup failed for 0 GPOs" log.txt
if %errorlevel% NEQ 0 goto error
goto OK
:error
echo error in GPO backup
rem === mailit parameters ===
SET MAILIT_SERVER=mail.server
SET MAILIT_FROM=GPO_bk@yourdomain.com
SET MAILIT_TO=s@yourdomain.com
SET MAILIT_SUBJ=Error in GPO Backup
SET MAILIT_MSGTEXT=There are errors in GPO backup, see attached log.
SET MAILIT_ATTACH=D:\Work\GPO_Backup\log.txt
D:\Work\GPO_Backup\MAILIT.exe
goto end
:OK
Set MONTH=%DATE:~4,2%
Set DAY=%DATE:~7,2%
Set YEAR=%DATE:~10,4%
7z.exe a -r "D:\Backup\GPO\GPO_%DAY%-%MONTH%-%YEAR%.zip" D:\Work\GPO_Backup\Temp\*.*
if %errorlevel%==0 goto end
rem === mailit parameters ===
SET MAILIT_SERVER=mail.server
SET MAILIT_FROM=GPO_bk@yourdomain.com
SET MAILIT_TO=s@yourdomain.com
SET MAILIT_SUBJ=Error in GPO Backup (7zip)
SET MAILIT_MSGTEXT=There are errors in GPO backup (7zip)
SET MAILIT_ATTACH=
D:\Work\GPO_Backup\MAILIT.exe
goto end
:end
====================================================
No comments:
Post a Comment