3

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?

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

Use

powershell.exe -ExecutionPolicy Bypass -File "C:\dir name\test.ps1"

Of course, replace C:\dir name\test.ps1 with the path and filename of the script you want to run, enclosed in " (double quotes).

Alternatively, start PowerShell in its own window, then run the script.

Comments

0

On macOS:

  1. Use Homebrew to install Powershell:

    brew install --cask powershell

  2. Switch to Powershell:

    pwsh

  3. Execute the script:

    ./Test.ps1

Comments

-1

My PowerShell script (Test.ps1):

echo "trying to test something"

I can execute it in cmd with this command:

.\Test.ps1

My output:

trying to test something

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.