?
Solved

help with script that backs up GPOs

Posted on 2014-12-14
5
Medium Priority
?
234 Views
Last Modified: 2014-12-22
Hello,
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
0
Comment
Question by:claudiamcse
5 Comments
 
LVL 24

Expert Comment

by:VB ITS
ID: 40499859
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: http://technet.microsoft.com/en-us/library/ee176961.aspx

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.
0
 
LVL 29

Accepted Solution

by:
Dan McFadden earned 2000 total points
ID: 40499865
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.

Dan

Dan
0
 

Expert Comment

by:creative555
ID: 40501447
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!
0
 
LVL 29

Expert Comment

by:Dan McFadden
ID: 40502128
FYI: Opening the command prompt and running the command PowerShell, puts you into the PowerShell environment.  Just without any of the predefined PS preferences.

Dan
0
 

Author Closing Comment

by:claudiamcse
ID: 40513337
Thank you DAN!
Great answer. It worked!
0

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
The article explains the process to deploy a Self-Service password reset portal I developed a few years ago. Hopefully, it will prove useful to someone.  Any comments, bug reports etc. are welcome...
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

594 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question