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

Comments

Please log in to comment

Community Chosen Answer

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"
Answered 02/11/2011 by: dchristian
Red Belt

Please log in to comment
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

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"
Answered 02/11/2011 by: cserrins
Red Belt

Please log in to comment
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?
Answered 02/11/2011 by: jmcelvoy
Second Degree Blue Belt

Please log in to comment
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.
Answered 02/11/2011 by: cserrins
Red Belt

Please log in to comment
0
Picked up the tip from [link]http://powershell.com/cs/[/link].

They got a great RSS feed!
Answered 02/11/2011 by: dchristian
Red Belt

Please log in to comment
0
WOW, great resource, thank you dchristian.
Answered 02/11/2011 by: cserrins
Red Belt

Please log in to comment
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.
Answered 02/11/2011 by: jmcelvoy
Second Degree Blue Belt

Please log in to comment
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.
Answered 02/11/2011 by: cserrins
Red Belt

Please log in to comment
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.
Answered 02/11/2011 by: jmcelvoy
Second Degree Blue Belt

Please log in to comment
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.
Answered 02/23/2011 by: ncsutmf
Second Degree Green Belt

Please log in to comment
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
Answered 04/15/2015 by: ronfalkoff
Third Degree Blue Belt

Please log in to comment
Answer this question or Comment on this question for clarity

Share