Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Windows » How to pause a PowerShell script
  • microsoft
    Fix EFI network timeout on VMware Workstation Virtualization
  • How to use Netstat.exe to confirm which Program uses or blocks a port
    How to use Netstat.exe to confirm which Program uses or blocks a port Linux
  • Certificate does not contain the private key
    Server Certificate could not be updated: Private key does not match Windows Server
  • Fix Windows Installer Service Could Not Be Accessed Error
    How to Fix the “Windows Installer Service Could Not Be Accessed” Error While Installing an Application Windows
  • Synology Diskstaion update to latest version 7.3
    Download and update Synology DiskStation NAS to DSM 7.3 Storage
  • Feature image msert tool
    How to remove malware using Microsoft Safety Scanner on Windows 10 and 11 Security | Vulnerability Scans and Assessment
  • GetScreen796zg65
    Getscreen.me: Flexible Remote Access Software For Customer Support Reviews
  • powershell
    Set PowerShell Execution Policy via Windows Settings Windows

How to pause a PowerShell script

Posted on 09/10/202015/02/2025 Christian By Christian No Comments on How to pause a PowerShell script
PowerShell script pause

PowerShell is a cross-platform task automation and configuration management framework, consisting of a command-line shell and scripting language. Unlike most shells, which accept and return text, PowerShell is built on top of the . NET Common Language Runtime (CLR), and accepts and returns . NET objects. In this post, we will discuss How to pause a PowerShell script. Please see the difference between testing and debugging, and how to debug a PowerShell script.

You may be amazed to know that to pause a PowerShell script is not as easy and has nothing equivalent to cmd.exe’s “Pause” command. I will discuss various ways to implement the pause function in a PowerShell script.

Why perform a PowerShell Pause operation?

In PowerShell scripts, the Pause or Break command is used to introduce a pause or delay in the execution of the script. This is useful in scenarios when you want to allow the user to read output, review information, or take some action before the script proceeds.

Also, During script development, you might use Pause to temporarily stop the script execution to inspect variables, output, or the state of the system.

That is, it is used to halt the execution of a script or a sequence of commands until the user manually resumes it. It is used for displaying information and waiting for the user to acknowledge or proceed.

Note: You may have to set the Execution Policy for PowerShell to be able to run the PowerShell script. Also, you must run PowerShell as an Administrator.

Please see How to setup PowerShell on a Linux server, How to Pause Windows Update via Windows Settings. See how to set PowerShell Execution Policy via Windows Settings.

Pause a PowerShell script

Method 1: Just enter the PowerShell script into your existing script to have it paused.

Function Pause($M="Press any key to continue . . . "){If($psISE){$S=New-Object -ComObject "WScript.Shell";$B=$S.Popup("Click OK to continue.",0,"Script Paused",0);Return};Write-Host -NoNewline $M;$I=16,17,18,20,91,92,93,144,145,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183;While($K.VirtualKeyCode -Eq $Null -Or $I -Contains $K.VirtualKeyCode){$K=$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")};Write-Host}
Delay PowerShell script

Method 2: What you could also try out is using the command below. The “/c” Carries out the command specified by string and then terminates | out-null pipes the output to out-null.

Where you’ll never see it If you want to see the “Press any key to continue…” message, remove the pipe but does not work in PowerShell ISE as it gets stuck.

cmd /c pause | out-null

Method 3: When the Pause command is encountered. PowerShell will display a message prompting the user to press Enter to continue. Below is an example of the operation.

Write-Host "This is some information."
Pause
Write-Host "The script continues from here."

In the above example, the script will display “This is some information.” and then pause execution until the user presses Enter. After pressing Enter, the script will print “The script continues from here as shown in this example.

Conclusion

It is worth noting that Pause is more interactive and useful when running scripts from the PowerShell console. Rather than in automated scripts where user interaction might not be desirable.

You could also use the Start-Sleep instead of Pause. If you need the script to wait for a specified period before proceeding.

I hope you found this blog post on how to pause a PowerShell script very helpful. If you have any questions, please let me know in the comment session.

5/5 - (1 vote)

Thank you for reading this post. Kindly share it with others.

  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on Bluesky (Opens in new window) Bluesky
  • Click to share on Threads (Opens in new window) Threads
  • Click to share on Nextdoor (Opens in new window) Nextdoor
Windows Tags:PowerShell, PowerShell version 7

Post navigation

Previous Post: MDT Invalid credentials: The network was not found
Next Post: Linux Machine: Is it Virtual or a Physical server

Related Posts

  • Windows Server vNext
    What’s New? Install Windows Server 2025 on Beelink EQ12 PC Windows
  • Interactive logon Message for Users
    Display interactive logon messages for Windows PCs via GPO Windows
  • Featured image System Tray icons
    How to Fix System Tray Icons not showing in Taskbar on Windows 11 Windows
  • settings app not working featured 800x400 1
    Disable or Remove Kiosk Mode Via the Local Settings Windows
  • Featured image
    Latest Improvement to File Explorer on Windows 11 Windows
  • Feature post
    Disable Bing Search in Windows: Quick Guide for Windows Windows

More Related Articles

Windows Server vNext What’s New? Install Windows Server 2025 on Beelink EQ12 PC Windows
Interactive logon Message for Users Display interactive logon messages for Windows PCs via GPO Windows
Featured image System Tray icons How to Fix System Tray Icons not showing in Taskbar on Windows 11 Windows
settings app not working featured 800x400 1 Disable or Remove Kiosk Mode Via the Local Settings Windows
Featured image Latest Improvement to File Explorer on Windows 11 Windows
Feature post Disable Bing Search in Windows: Quick Guide for Windows Windows

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a

  • microsoft
    Fix EFI network timeout on VMware Workstation Virtualization
  • How to use Netstat.exe to confirm which Program uses or blocks a port
    How to use Netstat.exe to confirm which Program uses or blocks a port Linux
  • Certificate does not contain the private key
    Server Certificate could not be updated: Private key does not match Windows Server
  • Fix Windows Installer Service Could Not Be Accessed Error
    How to Fix the “Windows Installer Service Could Not Be Accessed” Error While Installing an Application Windows
  • Synology Diskstaion update to latest version 7.3
    Download and update Synology DiskStation NAS to DSM 7.3 Storage
  • Feature image msert tool
    How to remove malware using Microsoft Safety Scanner on Windows 10 and 11 Security | Vulnerability Scans and Assessment
  • GetScreen796zg65
    Getscreen.me: Flexible Remote Access Software For Customer Support Reviews
  • powershell
    Set PowerShell Execution Policy via Windows Settings Windows

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,839 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.