Solved

help with script that backs up GPOs

Posted on 2014-12-14
5
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 27

Accepted Solution

by:
Dan McFadden earned 500 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 27

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

763 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