Silent installation by using Powershell scripting

前端 未结 2 1614
轮回少年
轮回少年 2021-01-16 16:39

I am trying to install one client\'s software by using PowerShell silent scripting. Below is the script which I have created and its not working and throwing errors like be

2条回答
  •  无人共我
    2021-01-16 17:21

    There are several things you may want to fix in your code:

    • $args is an automatic variable. Don't try to overwrite it. Use a different variable name, e.g. $params. As others have already mentioned, put the parameters in quotes when defining the array.
    • Unless you have specific reasons to use Start-Process it's easier to use the call operator and splatting.
    • External programs don't throw PowerShell exceptions, so using try/catch on them is pointless.
    • PowerShell automatically records the exit code of an external program in the automatic variable $LastExitCode.
    $installer = 'C:\Software\Software.exe'
    $params = '/S', '/L1033', '-INSTALL_TYPE=PRESERVE_VERSION',
              'START_MENU=AStartMenuFolder\Software\production'
    
    & $Installer @params
    if ($LastExitCode -eq 0) {
        [Windows.MessageBox]::Show('Installation Completed Successfully')
    } else {
        [Windows.MessageBox]::Show('Installation Failled')
    }
    

提交回复
热议问题