Friday, September 20, 2013

Quick Script: Run a MSI installer with a transform using Powershell

function Run-MsiExec($installShare, $msiPackage, $Transform, $options){
       $Arguments = "/i `"$env:temp\$msiPackage`" ALLUSERS=2 TRANSFORMS=`"$env:temp\$Transform`" /qn $options"
      
       Copy-Item "$installShare\$msiPackage" "$env:temp\$msiPackage"

       if($Transform){
              Copy-Item "$installShare\$Transform" "$env:temp\$Transform"
       }else{
              $Arguments = "/i `"$env:temp\$msiPackage`" ALLUSERS=2 /qn $options"
       }
       Write-Host "Installing $msiPackage"
    Write-Host "Start-Process -FilePath 'msiexec.exe' -ArgumentList "$Arguments" -Wait -Passthru"
       return (Start-Process -FilePath "msiexec.exe" -ArgumentList "$Arguments" -Wait -Passthru).ExitCode

No comments:

Post a Comment