help with script that backs up GPOs

I need help with this script that suppose to back up GPOs. It is not working.....What are the requirements to run this script? Where should I run it from?

when I run this script, all is does is opening the notpad with the script inside. It doesn't run.
Do I need to run it from server with Group Policy Management Tools installed, etc?
I did change the directory to my server directory.

Thank you!

# GPOBackupSamp.PS1  
# Script By: Tim B.
# This script Backup all GPOs and save it to a folder named as the current date.
# Change the Path "\\server\c$\Backup\GroupPolicies\$date" to your server path
Import-Module grouppolicy
$date = get-date -format M.d.yyyy
New-Item -Path \\server\c$\Backup\GroupPolicies\$date -ItemType directory
Backup-Gpo -All -Path \\server\c$\Backup\GroupPolicies\$date
Who is Participating?
Dan McFaddenSystems EngineerCommented:
When "running" the script, how are you running it?  You cannot just double-click on the script, you must run it from the powershell console.

1. Open a command prompt
2. type:  powershell and hit enter.  You will get a command prompt that looks like:  PS C:\...
3. from this command prompt, navigate to the location of your script
4. type:  .\<TheNameOfYourScriptGoesHere>.ps1 and hit enter

You could run the script from a DC or another server with the Task Scheduler.  The action would be:

- Start a program
- Program/Script:  C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
- Add arguments:  -NoLogo -NonInteractive -File "C:\scripts\<TheNameOfYourScriptGoesHere>.ps1"

As for the script:  it looks fine.


VB ITSSpecialist ConsultantCommented:
Sounds like you have associated the .PS1 file extension with Notepad. Try this:

Open PowerShell from the Start Menu (right click > Run as Administrator may be necessary) > navigate to the directory where the .PS1 script is stored > type in ,\GPOBackupSamp.PS1 > hit Enter

The script should then run. If you get any errors stating the execution of scripts is disabled then you may need to use the Set-ExecutionPolicy command to change the policy level. See here for the various execution policies which you can set it to:

I would recommend you use RemoteSigned, however there may be instances where you'll have to set it to Unrestricted to get the script to run.
Thank you so much. We changed the account to a different name and I contacted the exchange admins to grant you points because this account is already closed. But both answers answered my question. Had to run it from powershell not from the cmd prompt! Back up of GPO was successful!
Dan McFaddenSystems EngineerCommented:
FYI: Opening the command prompt and running the command PowerShell, puts you into the PowerShell environment.  Just without any of the predefined PS preferences.

claudiamcseAuthor Commented:
Thank you DAN!
Great answer. It worked!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.