1

I am having an issue with Windows Installer popup when running my script.

My script

function InstallMyMsi {
    $File='C:\\my\\path\\my msi file.msi'
    $DT = Get-Date -Format "yyyyMMdd_HHmm"
    $Log = "C:\\my\\other_path\\Log_$DT.log"
    
    $Params = "/L*V $Log", '/i', $File, '/qn!', '/quiet', '/passive'
    $p = Start-Process `
        'msiexec.exe' `
        -ArgumentList $Params `
        -NoNewWindow `
        -Wait `
        -PassThru

    return $p.ExitCode
}

InstallMyMsi

I have tried different combinations of arguments with no luck.

Any ideas?

Edit: The file name of the msi contains space. I have edited that part, could this be the cause of the issue?

user16908085
  • 95
  • 10
  • 1
    PowerShell does not need for you to escape the \. Change \\ to \ in $File and $Log – Daniel Sep 29 '21 at 14:08
  • 1
    (Daniel is correct, but the double backlashes are benign and don't explain your problem.) If the pop-up dialog is the standard dialog explaining the _command-line syntax_, the implication is that your `msiexec` call has a _syntax problem_. – mklement0 Sep 29 '21 at 14:12
  • As an aside: While passing the pass-through arguments _individually_ to `-ArgumentList` may be conceptually preferable, a [long-standing bug](https://github.com/PowerShell/PowerShell/issues/5576) unfortunately makes it better to encode all arguments in a _single string_ - see [this answer](https://stackoverflow.com/a/62784608/45375). – mklement0 Sep 29 '21 at 14:12
  • I have made the changes as per suggestion, but the issue still persists. I managed to get it to run when I replaced space with an underscore. But I don't understand why this works – user16908085 Sep 29 '21 at 14:31
  • Is `/qn!` a valid switch or should it just be `/qn`? – Daniel Sep 29 '21 at 14:33
  • /qn! is not valid. I updated my post. – Seb Oct 01 '21 at 17:13

1 Answers1

1

I have run into this before. It's often easier to build a string and pass it that way. Also, you may need to surround your argument to /i with quotes as some paths to your installer may have a space it in.

function InstallMyMsi {
    $File='C:\\my\\path\\file.msi'
    $DT = Get-Date -Format "yyyyMMdd_HHmm"
    $Log = "C:\\my\\other_path\\Log_$DT.log"

    $Params = "/L*V $Log /i `"$File`" /qn /quiet /passive"
    $p = Start-Process `
        'msiexec.exe' `
        -ArgumentList $Params `
        -NoNewWindow `
        -Wait `
        -PassThru

    return $p.ExitCode
}

InstallMyMsi
Seb
  • 179
  • 2
  • 6