Skip to content

Instantly share code, notes, and snippets.

@csev1755
Created November 29, 2021 15:30
Show Gist options
  • Save csev1755/885ab7f0029e495b5758dd04f05128e7 to your computer and use it in GitHub Desktop.
Save csev1755/885ab7f0029e495b5758dd04f05128e7 to your computer and use it in GitHub Desktop.
Let user skip certain parts of script in PowerShell
function Get-Choice {
param ($question)
while ($True) {
$choice = Read-Host ($question + " (y/n)")
if ($choice.ToLower() -eq "y") {return $True}
elseif ($choice.ToLower() -eq "n") {break}
else {continue}
}
}
if (Get-Choice "Write test output?") {
Write-Output "Test"
}
# Write test output? (y/n): y
# Test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment