Solved

run a powershell script

Posted on 2012-04-05
3
697 Views
Last Modified: 2012-06-27
Hi don't know if this is possible but running a small domain and I have a powershell script to change a few permissions and delete a file and would like to push it out via group policy. So i created a new policy added the script as a startup script in the computer section and selected the GPO option to run powershell scripts as unrestricted. Problem is the script will still not run from GP (even though it runs fine when I right click it and select run with powershell form the network share). After a little research I have discovered this is because the script is still pausing and asking for permission to run and to overcome this I need to sign the script. I don't have a CA and it seems a little much to but a certificate and go though all that mess just to run a simple script. Is there a way around this issue that does not involve me going round every machine and running the script manually?
0
Comment
Question by:Dead_Eyes
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Dale Harris
ID: 37812569
Our workaround was to run a .bat file that runs a powershell script file with the appropriate executionpolicy.  Example:

@echo off
powershell.exe -windowstyle hidden -executionpolicy unrestricted "Scriptname.ps1"

Try that.
0
 

Author Comment

by:Dead_Eyes
ID: 37812626
Thanks for the fast reply, do you know if that would that work for:

@echo off
powershell.exe -windowstyle hidden -executionpolicy unrestricted "\\domian\netlgon\Scriptname.ps1"

and do need to change the exectionpolicy to unrestricted on the GPO or can i just leave it is restricted and the bat file will sort it out? (seems like a good security loophole if you can just use a bat file to change the execution policy lol)
0
 
LVL 16

Accepted Solution

by:
Dale Harris earned 500 total points
ID: 37812651
Yeah you're going to be able to easily run it from a domain location.  If there's an issue, you might have to specify -script and then the location.  Just do a "powershell.exe /?" in your powershell window.  This will allow you to see all the different parameters and arguments needed.  Once you get it, you're done.

Also, you can go ahead and remove the GPO executionpolicy setting, because you're right, all you have to do is call powershell with an argument of no executionpolicy and you're golden :)

-Dale Harris
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need some powershell help please 5 62
Powershell: how to append to a CSV instead of out to a new CSV 5 31
Powershell to query AD 3 33
Changing out of office on 365 5 40
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

789 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