Search code examples
powershellcmdexec

how to exec ps1 file from cmd?


I have a ps1 file, Test.ps1, which I need to exec from cmd. For test purposes this file only has 1 line:

write "ps1 test successful"

I was trying to exec this ps1 file from cmd. I googled and it seemed that including the following line might help:

Set-ExecutionPolicy RemoteSigned
write "ps1 test successful"

However I still can't exec this test. I've tried:

powershell Test
powershell Test.ps1
Test
Test.ps1

The cmd path context is set to the dir in which the ps1 script resides. Any idea what I might be doing wrong here?


Solution

  • Does this work?

    Powershell -ExecutionPolicy Bypass -File .\Test.ps1

    I've done this before with a .bat file, and this was the syntax used. In this instance, you're running from within the same directory as the powershell script (otherwise adjust the filename argument as necessary). And you may need to be running the CMD prompt as admin, if you aren't already.