When I try to run Powershell script on my work computer the screen flashes and then close immediately.

Destin, Ernest 0 Reputation points
2025-09-23T15:22:00.3433333+00:00

When I try to run Powershell script on my work computer the screen flashes and then close immediately. This happened before when I first started on my old PC. This issue is happening again on my new PC. it appears that every time I have a new device it does that. Help Please.

Windows for business | Windows Client for IT Pros | Performance | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Domic Vo 11,150 Reputation points Independent Advisor
    2025-09-23T17:15:08.9666667+00:00

    Dear Destin, Ernest,

    Thank you for reaching out regarding the issue you're experiencing when running PowerShell scripts on your work computer. We understand how frustrating it can be when the script window flashes and closes unexpectedly, especially when this behavior recurs across devices.

    This issue is often related to script execution policies or how the script is launched. Below are a few steps that may help resolve the problem:

    Recommended Steps to Troubleshoot:

    1. Check Script Execution Policy Open PowerShell as Administrator. Run the command:
      • Code
             Get-ExecutionPolicy
        
        If the result is Restricted, update it by running: Code
             Set-ExecutionPolicy RemoteSigned
        
        Confirm the change when prompted.
    2. Run Script from PowerShell Console Instead of double-clicking the .ps1 file, open PowerShell manually. Navigate to the script location using cd and run the script by typing:
      • Code
             .\YourScriptName.ps1
        
    3. Add a Pause to the Script If the script completes instantly, add the following line at the end to keep the window open:
      • Code
             Read-Host "Press Enter to exit"
        
    4. Verify File Extension and Content Ensure the file is saved with a .ps1 extension and contains valid PowerShell syntax. Avoid launching the script from environments that auto-close (e.g., File Explorer).

    Please let me know if any of these steps help resolve the issue. If you find this answer helpful, feel free to hit "Accept Answer" so others can benefit too 😊. T&B,

    Domic Vo

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.