-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWait-ForKey.ps1
More file actions
52 lines (41 loc) · 1.41 KB
/
Wait-ForKey.ps1
File metadata and controls
52 lines (41 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<#
.NOTES
RUNNING SCRIPTS CARRIES RISK. ALWAYS REVIEW SCRIPTS BEFORE RUNNING THEM ON YOUR SYSTEM.
IF IN DOUBT, COPY AND PASTE THE SCRIPT INTO A SERVICE LIKE CHATGPT AND ASK IF IT COULD BE HARMFUL.
.SYNOPSIS
Demo of a PowerShell script that waits for user to press any key before exiting
.DESCRIPTION
Demonstration PowerShell script that waits for user to press any key before the script exits.
.PARAMETER NonInteractive
Prevents prompts for user input. Inteded for automated execution.
.PARAMETER Text
The text string to be displayed by the demo script
.NOTES
Author : Stuart Bell
License : MIT
Repository : https://github.com/stu-bell/powershell-scripts
.LINK
https://github.com/stu-bell/powershell-scripts
#>
param(
[switch]
[Parameter(HelpMessage = "Prevents prompts for user input. Inteded for automated execution.")]
$NonInteractive,
[string]
[Parameter(HelpMessage = "Text to be printed")]
$Text="Hello!"
)
# Waits for user input before continuing, unless script paramter $NonInteractive is true
function Wait-ForKey {
param (
[string]$Message = "Press any key to continue..."
)
if (-not $Global:NonInteractive) {
Write-Host $Message
[void][System.Console]::ReadKey($true)
}
}
# Check that the arguments are passed through
Write-Host "You entered: $Text"
# Wait before exiting
Wait-ForKey -Message "Press any key to exit..."