We have Powershell scripts which are run on remote workstations via a private tool (and via PSEXEC). All feedback (messages, errors) is given in the CMD window. The problem is that when a script uses a menu (via "Read-Host" + "Switch"), this menu sometimes loops endlessly. The CMD sends data that the Powershell interprets as a user choice, and as a result, it enters the "Default" part of the "Switch" and does so endlessly.
$choix2 = Read-Host "Faire un choix : O/N"
switch ($choix2) {
O {
Action
}
N {
Action
}
default {
Write-Host "Invalid choice"
Pause
}
}
In "Default", the "PAUSE" command is used to limit this problem. When the CMD sends data, the "PAUSE" stops and the user can enter a choice. But sometimes it doesn't work and the menu loops back to "Default".
I'd like to know if there's a more functional method of correcting this problem completely. To completely remove this "parasitic" data, sent by cmd, which is blocking me from using the Powershell menus.
Regards