Search code examples
powershellread-host

Edit pause message in powershell ISE


So, as the title says, I would like to change the message from "press enter to continue", to "press enter to return to the menu". is this possible? if so can someone hook me up with a script line for it? I can post the code here if this may help. thank you in advance.


Solution

  • Since pause is a function, it can be overridden. Let's first see the command:

    Get-Command -Name pause | select *
    
    HelpUri             :
    ScriptBlock         : $null = Read-Host 'Press Enter to continue...'
    CmdletBinding       : False
    DefaultParameterSet :
    Definition          : $null = Read-Host 'Press Enter to continue...'
    Options             : None
    ...
    

    As can be seen, the ScriptBlock is quite simple. A change in function definition is like so,

    PS C:\> pause
    Press Enter to continue...:
    PS C:\> function pause{ $null = Read-Host 'Press Any Key or Enter to continue...' }
    PS C:\> pause
    Press Any Key or Enter to continue...:
    PS C:\>
    

    Since it's a built-in function, overriding the message must be done in profile or script file. Otherwise, the default text will re-emerge.