If PowerShell flashes open and closes, first separate a finished script from a startup failure: launch powershell.exe from an existing terminal, and if it still exits instantly, treat that as a startup fault. The quickest first check is a tiny script opened with -NoExit, so you can see whether the shell, the shortcut, or the script is ending the window. The window closing right after a command finishes usually means the script ended normally, while an immediate exit at launch points to a startup or command-line problem.
PowerShell launch decision table
This table separates a normal script exit from a launch problem. Use the symptom you can observe, then try the exact command shown. Do not jump to cache cleanup or repairs before you check the launch path, startup entries, and script syntax.
| Symptom | Likely cause | What to test next | Exact launch command to try | Safest next action |
|---|---|---|---|---|
| Script window closes normally after the work finishes | The script completed successfully | Run the same script with a tiny test file to confirm the launcher, not the script, is closing the window | powershell.exe -NoExit -ExecutionPolicy Bypass -File "C:\Scripts\simple.ps1" | Inspect script syntax only if the test file also closes |
| Shortcut closes because the console disappears right away | -NoExit is missing, or -File is in the wrong order | Fix the shortcut target and re-run with a quoted full script path | "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoExit -File "C:\Scripts\simple.ps1" |
Inspect script syntax if the fixed shortcut still closes |
| PowerShell flashes and exits the moment you open it | Profile, execution policy, shell corruption, or a launch crash | Open it from cmd so you can see any message; then test a clean launch without a profile | powershell.exe -NoExit -NoProfile | Inspect profile.ps1 first, then cache folders and repair tools if needed |
| PowerShell pops up at sign-in or startup | A scheduled task, Startup app, or vendor updater is launching it | Check Task Scheduler and Startup apps before deleting profiles or caches | pwsh -NoExit or powershell.exe -NoExit from the suspected task entry | Inspect Task Scheduler and Startup apps |
Why PowerShell closes right away
When a PowerShell window appears and disappears fast, the cause is usually one of two things: a script reached the end and exited normally, or the shell failed during startup. The branch you follow depends on whether you launched powershell.exe, pwsh, or a shortcut that points to a .ps1 file.
PowerShell 5.1 and PowerShell 7 are separate executables. powershell.exe starts Windows PowerShell 5.1, while pwsh starts PowerShell 7. A shortcut that works for one may not behave the same with the other, so identify the launcher before you change anything else. (Microsoft Learn) (Microsoft Learn)
Likely causes
- A script finished normally and closed the window.
- A shortcut target is missing -NoExit or places -File incorrectly.
- A profile file, execution policy, or syntax problem stops startup.
- A scheduled task, Startup app, or updater is opening PowerShell on its own.
Say your shortcut points to a long script and the console vanishes in less than a second. That can be normal if the script completes, but it can also mean the command line is wrong. A tiny file named simple.ps1 that contains Write-Host "test" is the fastest way to tell the difference.
How to stop a script window from closing
Use -NoExit when you want the session to stay open after a command or script finishes. Put -NoExit before -File, and use the full executable path plus a full script path in quotes. For PowerShell 7, use pwsh; for Windows PowerShell 5.1, use powershell.exe.
Fix steps
- Create a test file named simple.ps1 with one line: Write-Host "test".
- Open Run and launch Windows PowerShell with: "
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"-NoExit -File "C:\Scripts\simple.ps1". - If you are using PowerShell 7, try: "C:\Program Files\PowerShell\7\pwsh.exe" -NoExit -File "C:\Scripts\simple.ps1".
- If the test window stays open, replace "C:\Scripts\simple.ps1" with your real script path, still in quotes.
- If a shortcut is involved, replace any relative path with a full path in the shortcut target field.
- If the script should run even when policy blocks it, test the launch with -ExecutionPolicy Bypass before -File.
A common first-time mistake is putting -NoExit after -File. That order can fail to keep the window open because the script argument should follow the launcher options. Keep the executable path first, then -NoExit, then -ExecutionPolicy if needed, then -File and the quoted script path.
How do you fix startup and profile problems?
If PowerShell opens and closes before you can type anything, a profile file or policy setting may be ending the session early. Start by checking the profile that matches the launcher you used, then test with -NoProfile so you can see whether the profile is the trigger.
Fix steps: open Windows PowerShell with: powershell.exe
- Open Windows PowerShell with: powershell.exe -NoExit -NoProfile.
- If that stays open, inspect %UserProfile%\Documents\WindowsPowerShell\profile.ps1 for startup commands that exit the shell, clear the screen, or launch another script.
- If you open PowerShell 7, check the matching PowerShell 7 profile path instead of the Windows PowerShell profile.
- If a script is blocked, test the same launch with -ExecutionPolicy Bypass or -ExecutionPolicy Unrestricted.
- Remove or rename only the line or command that changes startup behavior; do not delete the whole profile unless you have a backup.
Suppose a profile runs a module import and the window closes before the prompt appears. That points to startup code, not a random crash. A clean -NoProfile launch that stays open strongly suggests the profile is the first file to inspect.
Why does PowerShell open at startup?
Recurring pop-ups usually come from Task Scheduler, Startup apps, or a vendor updater that launches powershell.exe or pwsh without asking. Check those locations before you touch cache folders or system files, because they are common sources of repeat launches.
Fix steps: open Task Scheduler and review
- Open Task Scheduler and review tasks with triggers for At log on or At startup.
- Open Task Manager > Startup apps and look for any PowerShell entry or updater that calls a script.
- Check the shell:startup folder and remove any shortcut that points to powershell.exe or pwsh.
- If the source is still unclear, perform a clean boot and retest the sign-in behavior.
- If the pop-up returns after a vendor app update, inspect that updater first.
Windows PowerShell can also show an update message at startup in some cases, and that message cannot be removed. If the window contains only that notice and then closes, the message itself is not the fault. Look for the process that starts it, not the message text.
What if PowerShell still closes?
If the launcher is correct, startup items are clean, and the profile is not the cause, move to repair and cache cleanup. Use SFC and DISM first. Clear only the safe PowerShell cache files named ModuleAnalysisCache-* and StartupProfileData-* after you have ruled out startup tasks and startup apps.
Fix steps: open an elevated Command Prompt
- Open an elevated Command Prompt.
- Run:
sfc /scannow - Then run:
DISM /Online /Cleanup-Image /RestoreHealth - If PowerShell still fails, close PowerShell-related processes and clear the user cache files ModuleAnalysisCache-* and StartupProfileData-*.
- If the issue affects only pwsh or only powershell.exe, treat it as version-specific and reinstall that branch instead of guessing.
Do not delete profile files or cache files before checking Task Scheduler and Startup apps. Those startup sources explain many repeat launches, while cache cleanup only helps after the source is ruled out. If SFC and DISM report unrepairable damage, a repair install or reinstall becomes the next sensible step.
Frequently asked questions
Why does powershell keep closing?
Most often, the window closes because the script finished or because the launch command is wrong. Test with powershell.exe -NoExit -File "C:\Scripts\simple.ps1". If that stays open, the issue is likely in the original script or shortcut, not PowerShell itself.
Why does my powershell keep opening?
Check Task Scheduler, Task Manager > Startup apps, and shell:startup for entries that call powershell.exe or pwsh. A recurring pop-up usually comes from sign-in or startup automation, not from a random desktop glitch.
What makes PowerShell open and close immediately
A bad shortcut target, a profile file, or execution policy can end the session before the prompt appears. Try powershell.exe -NoExit -NoProfile. If that opens normally, inspect %UserProfile%\Documents\WindowsPowerShell\profile.ps1 next.
Why does Windows PowerShell keep popping up and closing?
That pattern usually points to a startup task or updater launching powershell.exe in the background. Check Task Scheduler first, then Startup apps, then the shell:startup folder. If the source is still unclear, a clean boot helps isolate the culprit.