Why Does My PowerShell Script Close Immediately When I Double-Click It?

0
0
Asked By TechieWizard42 On

I have a PowerShell script that runs fine in the IDE or terminal, but it closes immediately when I try to open it by double-clicking the file. Even when I include commands like pause and Read-Host, the window still closes right away. Here's a simple version of my script that works perfectly in the terminal:
echo "test"
pause
pause
Read-Host -Prompt "Press Enter to exit".
I discovered that the issue might be due to the script being located in a folder that has a space in its name. Can anyone help me figure this out?

1 Answer

Answered By SkepticalCoder99 On

PowerShell scripts aren't meant to be double-clickable by default. If yours opens in something else when you double-click, then you've likely changed something in your system settings. You might want to check the guide you followed to make those changes and either revert them or find another way to run your script. PowerShell really isn’t designed for that kind of usage.

CuriousDev27 -

So, does that mean a PS1 file will just open in Notepad by default?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.