Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

help with script that backs up GPOs

Posted on 2014-12-14
5
Medium Priority
?
230 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Here's a look at newsworthy articles and community happenings during the last month.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
Loops Section Overview

782 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