22

I have a PowerShell script for building my project files, and I'd like to have capability to run it from my file manager's command line (and, possibly, make a shortcut to this script so I can start build from my desktop)
Any way to do this?

skevar7
  • 995
  • 1
  • 10
  • 21
  • 1
    I've started using PowerShell for a command prompt instead of cmd.exe/command.com. Provides all of the same functionality, but you get instant access to all of the PS capabilities, as well. – 3Dave Jul 24 '10 at 16:12

2 Answers2

40

If you're on PowerShell 2.0 use:

PowerShell.exe -File c:\users\john\myscript.ps1

If you're on 1.0 use:

PowerShell -Command "& {c:\users\john\myscript.ps1}"

Depending on what you do/load in your profile script you may also want to specify -NoProfile. Of course, if your script requires something that is loaded in your profile then don't use this parameter. Otherwise, it can speed up execution of your script a bit.

Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • In windows 10 this doesn't run by default, it's a matter of security! – AVEbrahimi Aug 06 '16 at 14:05
  • Yes but anyone using PowerShell is going to pretty quickly figure out they need to set the PowerShell execution policy to something other than `Restricted`. – Keith Hill Aug 08 '16 at 20:43
-9

invoke-command -computername -scriptblock{param()} -ArgumentList