Solved

How to run power shell script via GPO in a server 2003 environment

Posted on 2013-06-11
4
654 Views
Last Modified: 2013-07-30
Hi. I have a powershell script I intend to use to remove software from targeted computers within an OU. I have the commands to remove the software and they work (below). I wish to push this out via GPO but am unsure how. I know the execute command needs to be enabled on all client machines for power script to work so not sure what I can do here.

$app = Get-WmiObject –Class Win32_Product | Where-Object {
$_.Name –match “xxxx xxx xxxxxx”}
$app.uninstall()
0
Comment
Question by:MongolianNoseFlute
[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
4 Comments
 
LVL 30

Expert Comment

by:Randy Downs
ID: 39237824
Try this and just put your script in a .ps file.

http://serverfault.com/questions/372061/how-do-i-execute-a-powershell-script-via-group-policy

Check out this page: http://technet.microsoft.com/en-us/library/ee176949.aspx

In particular, I think you'd want to edit your machine start up GPO to run:

C:\windows\system32\windowspowerShell\v1.0\powershell.exe & "C:\script.ps1"
0
 

Author Comment

by:MongolianNoseFlute
ID: 39238044
Thanks for the reply but I am not entirely sure what to do here.
In GPO editor I can go to User configuration - Windows Settings - Scripts (logon/logoff) and point to my ps1 file which is in a shared folder but I know that will not work.
You say run: C:\windows\system32\windowspowerShell\v1.0\powershell.exe but how? I know I can make it run but how do I make it run and execute the script?

Thanks for the help!! :)
0
 
LVL 16

Expert Comment

by:ThinkPaper
ID: 39238074
In GPO editor, when you browse, it should automatically specify a location (i.e. domain.com\SYSVOL\Policies\{LONGSTRINGOFGPO}\User\Scripts\Logon\ )

Drop your PS1 file there, not on your share. It should sit where your GPO sits.

Are you running windows xp or windows 7?
With windows xp, make sure that powershell is installed on the workstations (available via Microsoft windows update - you should be able to simply approve this update), all you simply need to do is point to that PS1 file.

No need to put extra commands to run the powershell.

Making sure powershell is installed on older clients: (windows xp)
http://support.microsoft.com/kb/968929
0
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 39239242
You can call powershell from a .BAT file with just a single line like
powershell.exe -noninteractive -file \\server\Scripts\yourscript.ps1
Configure your GPO to run the .BAT file which will execute the PS script.
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

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…
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
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 …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

729 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