mercredi 9 juin 2021

Making a PowerShell more efficient other than if statements

I have a script here that does its job for the most part. I am new to PowerShell scripting, so I am trying to get an outside view of what I should change.

The first part of the script asks the user if they would like to install the program or not.

$<application> = Read-Host -Prompt 'Would you like to install <>? Please type Yes or No'

This then leads to an if else statement

if ( $<application> -eq 'Yes' )
{
 start-process <application.exe>
 Start-Sleep -s 30
}
else
{
  Write-Host "Installation of <Application> was skipped"
}

The reason I have start sleep is because it opens up an application one at a time. You have 30 seconds to setup the application which doesn't seem efficient

  • My questions are
    • Is there any way to do this without a sea of if statements? I know there is a way with a csv file but I am looking for alternatives. I like how the script asks if you should install a program or not
    • Is there anyway to stop the Start- Sleep process when the application is done? So the user doesn't feel rushed on one application?

Thank you.

Aucun commentaire:

Enregistrer un commentaire