Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7816941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:03:26+00:00 2026-06-02T06:03:26+00:00

If I have a PowerShell window (at the PowerShell command prompt) on display it

  • 0

If I have a PowerShell window (at the PowerShell command prompt) on display it prevents the computer shutting down.

I.e. if I open a PowerShell window and then try to shutdown the server, I get the End Program popup saying Windows cannot end this program.

I get the same result if I start PowerShell from the start menu, from a cmd prompt and from a shortcut with -NoExit specified.

How can I get shutdown to automatically close a PowerShell window (if it is at the PowerShell prompt) in the same way as it would for a CMD window?

Alternatively, is it possible for PowerShell to detect when a shutdown has been initiated and therefore close itself?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:03:28+00:00Added an answer on June 2, 2026 at 6:03 am

    This question was answered on Server Fault, so here is my solution test code:

    Write-Host "PowerShellBlockingShutdown.ps1 Started"
    
    $global:shuttingDown = $false
    $sysevent = [microsoft.win32.systemevents]
    Register-ObjectEvent -InputObject $sysevent -EventName "SessionEnding" -Action {$global:shuttingDown = $true; Write-Host "  SessionEnding"}
    Register-ObjectEvent -InputObject $sysevent -EventName "SessionEnded"  -Action {$global:shuttingDown = $true; Write-Host "  SessionEnded"}
    
    do {
        Start-Sleep -Seconds 3
        if ($global:shuttingDown) {break}
        Write-Host "  Waiting for Shutdown"
    } while ($true)
    
    Write-Host "PowerShellBlockingShutdown.ps1 Finished"
    

    Which seems to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have powershell version 2.0.0.1082 on my server. I want to import data from
I have a powershell command running when I execute a bat file, The command
I have a powershell script that runs fxcopcmd in the output window. Turns out
I have a couple of powershell command that are very simple. disable-mailbox dadelgad -confirm:$false
For some reason the Windows command prompt is special in that you have to
Does anyone have a Powershell script to change the credentials used by a Windows
I have PowerShell v2.0 installed and on top of that, PSCX is installed. PSCX
I am trying to have PowerShell unblock a file in Win2K8 R2. Does anyone
I have a PowerShell module called Test.psm1. I want to set a value on
How do I have a PowerShell script embedded within the same file as a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.