/build/static/layout/Breadcrumb_cap_w.png

How to run a Powershell command...

as a post installation script? I have a .ps1 file that has:
set-executionpolicy remotesigned -force
add-computer -domain mnb.local

Now I need to know how to get this to run. I can't just create a BAT Script as it will attempt to run these in a DOS windows. Do I upload my .ps1 and add it as an application?

0 Comments   [ + ] Show comments

Answers (11)

Posted by: dchristian 13 years ago
Red Belt
1
I've been using this in the k1000.

I haven't tested it in the k2000 but i think it'll work.

Add you script as an application and use this as the command line.

powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file "script.ps1"
Posted by: cserrins 13 years ago
Red Belt
0
dchristian, that is sweet, didn't know you could do that, I always write a script that changes the registry of the execution policy first, then run my .ps1 file

"HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell", "ExecutionPolicy", "REG_SZ", "RemoteSigned"
Posted by: jmcelvoy 13 years ago
Second Degree Blue Belt
0
So I'm assuming I would take out the set-executionpolicy remotesigned -force from my script and the "script.ps1" is the name of my file right?
Posted by: cserrins 13 years ago
Red Belt
0
That is correct, the execution policy must be set first, prior to running a .ps1 file, or in this case, as you are calling the file.
Posted by: dchristian 13 years ago
Red Belt
0
Picked up the tip from [link]http://powershell.com/cs/[/link].

They got a great RSS feed!
Posted by: cserrins 13 years ago
Red Belt
0
WOW, great resource, thank you dchristian.
Posted by: jmcelvoy 13 years ago
Second Degree Blue Belt
0
I created a batch file that says:
powershell.exe -command add-computer -domain domainname
pause

Named this JoinDomain.bat, saved to C:\ and added a RunOnce entry that called this file. It ran no problems. For some reason I didn't have to modify the executionpolicy calling the command from a batch file.
Posted by: cserrins 13 years ago
Red Belt
0
very strange indeed. If you did a fresh scripted install, you would have to set this execustion policy. Are you doing it to an image, because maybe it is set there already. You can go to the registry key I mentioned above to see what it is set to.
Posted by: jmcelvoy 13 years ago
Second Degree Blue Belt
0
I thought that at first so I removed the pc from the domain, ran set-executionpolicy restricted to set the policy back to restricted, then fired up powershell and tried running a ps1 script and it gave the message about scripts being disabled blah blah blah. I then added the RunOnce key and rebooted and it ran again no problem. It really is odd that I don't have to set the executionpolicy when doing this from a .bat file but I do have to set it before I can run it from a .ps1 file.
Posted by: ncsutmf 13 years ago
Green Belt
0
When you use the -command option for powershell.exe, you are not actually running a .ps1 file, so the execution policy does not apply.
Posted by: ronfalkoff 9 years ago
Green Belt
0

I have run into PowerShell issues if PowerShell is not launched as admin or elevated The command below will elevate PowerShell to admin and will allow more functionality... 

Start-Process PowerShell -Verb RunAs
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ