none
Powershell: Remote msi Installation

    Question

  • Hi, all

    I want to install a .msi a remote computer with powershell, and I need to be able to log the installation and also obtain installation result (return value) for further process. I've tried several ways, but none of them achieves both of the 2 goals.

    1. "Win32_Product" class 

    $win32Product=Get-WMIObject -ComputerName $hostname -List Win32_Product -Authority kerberos:$domainName\$hostname -Impersonation Delegate 

    $s.install("installer.msi", "MsiLogging=Iwe MsiLogFileLocation=c:\a.log",$true)

    using "Win32_Product" class can install successfully on a remote machine and obtain the installation result, but the argument of install method for logging("MsiLogging=Iwe MsiLogFileLocation=c:\a.log") seems doesn't work

    2. using "win32_process" class

    $win32Process=Get-WMIObject -ComputerName $hostname -List Win32_Process

    $win32Process.create('cmd /c msiexec /i  "C:\MSI\Install.msi" /q /lv c:\a.log')

    using "Win32_Product" class can install a msi on a remote machine and create log successfully, but it is not easy to obtain the installation result

    So is there any ways to do that? Thanks!

    Thursday, June 17, 2010 9:17 AM

All replies

  • Hi Frank,

    Try this

    $msi="C:\Test.msi"
    function LaunchProcessAndWait([string] $FileName, [string] $CommandLineArgs)
    {
        #preferences
        $ErrorActionPreference="Stop"
        Write-Host("Starting process $FileName")
        $p = Start-Process -FilePath $FileName -ArgumentList $CommandLineArgs -Wait -PassThru
        Write-Host("The process $FileName exit code is $($p.exitcode)")
        return $p.ExitCode;
    }
    $clargs = "/i "+ "`"$msi`"" + " /l* " + "`"C:\InstallLog.log`"" + " /passive /norestart ADDLOCAL=ALL"
    $exitCode = LaunchProcessAndWait "msiexec" $clargs
    if ($exitCode -ne 0)
    {   
        throw "failed to install !"
    }
    Get-Content "C:\InstallLog.log"

    Here you can place this code in a script block and use invoke-command to run this on remote computer.

    Hope this helps.

    Friday, June 18, 2010 12:21 PM