Solved

help with script that backs up GPOs

Posted on 2014-12-14
5
174 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 26

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 26

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now