S
S
swim3r2017-07-28 12:24:06
PowerShell
swim3r, 2017-07-28 12:24:06

How to repeat a block on error?

There is a script in PowerShell, it has an IF block, at the moment.
if the condition is true: asks for a password to connect to the SQL database and connects;

spoiler
IF (условие) {
запрос пароля
    try {подключение к базе}
    catch {не удалось подключится
               exit}
}

How can I make it so that if there is an error in entering a password, it would return back to the input request, and not complete the script?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2017-07-28
@tsklab

Use While with an attempt counter.

N
Newerindian, 2017-11-16
@Newerindian

Function AskAndCheck
{
$ask = Read-Host 'Type 1'
if ($ask -ne 1)
{
Write-Host 'fault'
AskAndCheck}
}
AskAndCheck

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question