Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Help with running powershell script at startup.

$
0
0

Hi All,

 

I need some help in creating a script that runs correctly.

I have a program that I want to run on startup on a number of machines. Each machine has different arguments of a command line file.

ie: PC-01 runs iexplore website1, PC-02 runs iexplore website2 etc.

I have created a switch statement along the lines of:

 

$workstation = $env:COMPUTERNAME

switch -Wildcard($workstation){

PC-01 {& "C:\Program Files (x86)\Internet Explorer\iexplore" "website1"; break}

PC-02 {&  "C:\Program Files (x86)\Internet Explorer\iexplore" "website2"; break}

...

PC-23 {&  "C:\Program Files (x86)\Internet Explorer\iexplore" "website23"; break}

}

Now testing this script on my workstation, as a local admin, it works perfectly fine. I've substituted my workstation id in for each of the switch statements and they all work.

However when I try to deploy it to other workstations, I'm getting an error message regarding running of scripts being denied due to execution policy on the local machine.

 

I deployed it using a couple of steps of 

 

copy from mymachine\c$\powershell\startup.ps1 to local workstation\c$\powershell 

copy mymachine\c$\powershell\startup.bat to \\localworkstation\c$\programdata\microsoft\window\sartmenu\program\startup\startup.bat

 

I ran the BAt file on startup and the Powershell prompt popped up and disappeared and nothing ran.

So digging into the issue I tried: 

Running the bat file as : start powershell -ExecutionPolicy ByPass -File c:\powershell\startup.ps1 failed due to the policy execution, as far as I'm aware.

I figured that if I ran a PS startup script (c:\Windows\System32\WindowsPowerShell\1.0\profile.ps1) which included the line: set-executionpolicy unrestricted I'd be fine. 

Nope, as it need to run as administrator to interact with the registry correctly

So I tried powershell -c start -verb runas powershell "c:\powershell\pave.ps1" and that pops up the UAC click OK to continue, which is impractical for a startup command.

I'm not messing with the UAC on the PC just to get this to work.

It's not as simple as changing the home pages of each machine as I'm only using iexplore as an example as I shouldn't put in the actual propriety software we use into an open forum.
Thanks for you help.
Pher.

Viewing all articles
Browse latest Browse all 6937

Trending Articles