The PowerShell cmdlets Stop-Service and Start-Service will wait until the services are fully stopped and started respectively.
function swit {
$choice = Read-Host 'Введите номер'
if ($choice -eq 9) {
Write-Host 'Выход'
}
elseif ($choice -ge 1 -and $choice -le 8) {
for ($i = 1; $i -lt 9; $i++) {
if ($i -eq $choice) {
Write-Host "$i.Нажали $i" -ForegroundColor Green
}
else {
Write-Host "$i.Нажали $i" -ForegroundColor Red
}
}
swit
}
else {
Write-Host 'Неверное значение, попробуйте еще раз.' -ForegroundColor Magenta
swit
}
}
swit