powershell - Simple increment/decrement counter -
i make simple counter in powershell. must prompt user whether they'd higher or lower number. starting number must 0, , can't lower 0 or higher 10. if user wants higher number, must increment number 1, if lower decrement 1. must able stop @ desired number. number can set registry value.
i don't know efficient way prompt user. can use read-host cmdlet ask if typed "higher" or "lower", there more efficient way accomplish this?
for example,
$i = 0 while (($i -gt 0) -or ($i -lt 10)){ $j = read-host "the current number $i, higher/lower number, or quit?" if ($j -eq "higher") { $i++ write-host "the current number $i" } elseif ($j -eq "lower") { $i-- write-host "the current number $i" } elseif ($j -eq "quit") { write-host "final number is: $i" break } }
how can this?
you use yes/no prompt window user input.
$a = new-object -comobject wscript.shell $intanswer = $a.popup("do want delete these files?", 0, "delete files", 4) if ($intanswer -eq 6) { $a.popup("you answered yes.") } else { $a.popup("you answered no.") }
if replace '3' in fourth parameter of popup() function yes, no, , cancel buttons in prompt window.
reference: provide yes/no prompt in windows powershell
Comments
Post a Comment