在 powershell ISE 中编辑暂停消息

Edit pause message in powershell ISE

所以,正如标题所说,我想将消息从 "press enter to continue" 更改为 "press enter to return to the menu"。这可能吗?如果可以,有人可以为我提供一个脚本行吗? 如果这可能有帮助,我可以 post 此处的代码。 提前谢谢你。

因为pause是一个函数,它可以被覆盖。先来看命令:

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
...

可以看出,ScriptBlock非常简单。函数定义的变化是这样的,

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:\>

由于它是内置函数,因此必须在配置文件或脚本文件中覆盖消息。否则,默认文本将重新出现。