Jump to content

Recommended Posts

Posted

Evening all

 

Right, so I'm trying to use PowerShell to set the screen resolution on the computers through the school depending on what they're attached too, but the script doesn't seem to be executing.

 

We're currently in a 2008R2 / W7 environment and I can't see the Windows Powershell option in the GPO to set the script execution and get and error when I download the ADM.

 

Any suggestions would be appreciated as it saves me the leg work of setting them all manually if I can get this to work. I'd assumed that anything running as a startup script would be perfectly fine anyway.

 

They run from a folder within NETLOGON on the PDC. I have the scripted function set-screenresolution.ps1 as per the scripting guys advice, and then another function to call that script and input the parameters I found online.

 

It works when I run it manually on a machine with the click R to run once options, so I guess that this is what's blocking the automation of it as a startup script.

 

Anywho, HELP! :)

 

Thanks All

Andy :cool:

Posted

Is the execution of scripts disabled on your system by any chance? Have you looked at the set-executionpolicy setting in powershell? (my first guess)

 

Can you get a screenshot of the error message?

Posted

It executes batch files on start up perfectly fine, and as it's a startup or login powershell script, nope, no error messages are seen, so I guess it's just falling over gracefully (which is better than it could be I suppose).

 

Also, I'm looking to try and set the execution policy via GPO as I already pointed out that it's asking for the run once prompt when I manually run the script. :)

 

The usual Windows Components / Windows PowerShell ADM doesn't appear to be in my GPO setup which I think is the crux of the problem, in that if I had that I could set the execution policy and everything would be fine.

Posted

Alternatively - you could try something like this!

 

powershell -noexit -c set-executionpolicy remotesigned -force; c:\pshell.ps1; set-executionpolicy default -force;

 

This opens powershell, sets the executionpolicy to allow script usage (other than the interwebs), runs the script, and then reset's your executionpolicy back to default.

 

This is a powershell security option to stop malicious scripts from being allowed to run, unless script execution is specifically allowed through powershell. it's set to dis-allowed by default.

 

Please note that the -noexit flag will leave the powershell session open.

  • Thanks 1
Posted

If I do use the noexit function, does this mean the PowerShell window would remain open on boot / login or would it close after running the commands? Or can I just tag an "Exit" onto the end so that it will close?

 

Thanks

Andy :)

Posted

hiya Andy - It's been a while since I used GPO for a powershell script so i don't remember entirely - the above is just an example on how to enable and dis-able script execution in a powershell session whilst running a script from a single line. I would suggest you take out the -noexit if you don't want the window to stay open anyway.

 

Let me know if this helps at all, and if not I'm happy to look further into it :)

  • Thanks 1
Posted
I can't see the Windows Powershell option in the GPO to set the script execution. I'd assumed that anything running as a startup script would be perfectly fine anyway.

You shouldn't need to worry about the execution policy.

 

... Group Policy scripts will always run, regardless of your local script execution policy. Even if your execution policy is restricted Group Policy scripts will still run using a Bypass policy. The assumption is that if you have setup a Group Policy to run a script, you know what the script will do and are taking adequate steps to protect it. (Source)
  • Thanks 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...