DEV Community

loading...
Cover image for How to run a PowerShell script ?

How to run a PowerShell script ?

courseprobe profile image Course Probe ・2 min read
  1. Launch Windows PowerShell, and wait a moment for the PS command prompt to appear

  2. Navigate to the directory where the script lives

  • PS> cd C:\my_path\yada_yada\ (enter)
  1. Execute the script:
  • PS> .\run_import_script.ps1 (enter)

Or: you can run the PowerShell script from cmd.exe like this:

powershell -noexit "& ""C:\my_path\yada_yada\run_import_script.ps1""" (enter)
Enter fullscreen mode Exit fullscreen mode

If you are on PowerShell 2.0, use PowerShell.exe’s -File parameter to invoke a script from another environment, like cmd.exe. For example:

Powershell.exe -File C:\my_path\yada_yada\run_import_script.ps1
Enter fullscreen mode Exit fullscreen mode

If you want to run a script without modifying the default script execution policy, you can use the bypass switch when launching Windows PowerShell.

powershell [-noexit] -executionpolicy bypass -File <Filename>
Enter fullscreen mode Exit fullscreen mode

Additional Resources:

Learning Windows PowerShell

Master Microsoft PowerShell

Operating Systems and You: Becoming a Power User

References:


Other Dev posts:

Discussion (0)

pic
Editor guide