Closed darchap closed 4 months ago
At first glance I would suggest to add a countdown and if the user does not provide any input in lets say 5 seconds, the script will terminate.
Nevertheless I'm not quite sure if that approach will meet the requirement you mentioned above "If you could find a way to ask to reinstall but not pause script execution"
Agreed, temporarily pausing script execution with a countdown as you mentioned is fine, we just don't want to pause it indefinitely. 😊 Not sure if that's possible though.
Yeah I need to figure out how to implement that, but I will try anyways. Thanks!!
I’ve managed to get it working. The only way I found was by creating an auxiliary function called Wait-ForKeyPress, which I think the name explains itself. I didn't know where to place this aux function, so it is above the original "if" statement, feel free to move it if you accept this PR in the end. I've also changed the version to 4.0.6 if you don't mind.
So, with all these modifications, if winget is installed and no -Force parameter detected, the script will terminate unless the 'y' key is pressed. I’ve added a 15-second timeout so that people who are executing this for the first time can read the warning and press the key before it terminates.
Thanks for working on this, but I've decided not to implement it.
The goal of PowerShell scripts is to minimize user interaction. Previously I had implemented an automatic Wait at the end of the script, and received many complaints from administrators describing how it impeded work flow because it delayed the time in which the script executed. When combined with other scripts, every second adds up.
As mentioned before, if this script were used solely by single-user environments, I could see how this would be advantageous and would implement it. But since the majority of users are systems Administrators who run the script without user interaction, this would delay script timing.
I've updated the if statement to check if winget is already installed. Users can still initiate the script with the "-Force" argument, or choose to reinstall winget directly without relaunching the script. Additionally, I've incorporated a do-while loop and converted the user input to lowercase to ensure that the input is always correct.