Powershell script works with MSI files but it does not work for msu,exe or mpi

This topic contains 6 replies, has 4 voices, and was last updated by  Adam Bertram 3 years, 1 month ago.

  • Author
  • #16724


    Can someone help get this script to work with msu, exe,msi ext?


    $workingDir = "c:\users\" + $me + "\Desktop\Remote_Install\"
    $inputFile = Read-Host "Where are the IP addresses (file)?"
    $inputFile = $workingdir + $inputFile
    $iplist = Get-Content $inputFile
    $srcFile = Read-Host "Which MSI file shall I load?"
    $source = $workingdir + $srcFile
    #$parameters = Read-Host "Any parameters?"
    $InstallString = 'msiexec /qn /norestart /lv c:\windows\temp\'+$srcFile+'.log /i "C:\windows\temp\' + $srcFile + '" '# + $parameters

    Write-Host Reading systems from: $inputfile

    foreach ($lineitem in $iplist) {
    $segments = $lineitem.Split(",")
    $destination = "\\" + $segments[0] + "\c$\windows\temp\"
    $wmipath = "\\" + $segments[0] + "\ROOT\CIMV2:Win32_Process"

    Write-host Running: $segments[0]
    Write-Host Copying from: $source
    Write-Host Copying to: $destination
    Copy-item $source $destination
    Write-Host Done!
    Write-Host Connecting via: $wmipath
    Write-Host Executing: $InstallString
    Write-Host Completed: $segments[0]

    Write-Host Done!

  • #16733

    Mathieu Buisson

    The cmdlet Invoke-Item should help you to make it work for any file type because it launches the default program for the file extension.

    For example :

    Invoke-Item YourFile.msi 

    (will open/execute the file with msiexec.exe)

    Invoke-Item YourFile.msu 

    (will open/execute the file using C:\Windows\System32\wusa.exe )

    Invoke-Item YourFile.exe 

    (will execute the file)

  • #16735

    Adam Bertram

    You really need to eliminate the prompts; use parameters instead. Also, ditch the Write-Host.; Use Write-Verbose. Here's a much better method. I just wrote on the fly and I have not tested it at all but even if it doesn't completely worked, this will get you very close. To do MSUs and EXEs, just modify the 'msiexec /i /qn...' remote process creation string.


    param (
    	[ValidateScript({Test-Path $_ -PathType 'Leaf' })]
    begin {
    process {
    	foreach ($Computer in $IpFilePath) {
    		foreach ($Msi in $MsiFilePath) {
    			if (Test-Connection $Computer -Quiet -Count 1) {
    				$Dir = 'C$\Windows\Temp'
    				if (Test-Path "\\$Computer\$Dir")
    					Copy-Item $Msi "\\$Computer\$Dir" -Force
    					([WMICLASS]"\\$Computer\Root\CIMV2:Win32_Process").create("msiexec /qn /norestart /lv c:\windows\temp\$Msi.log /i `"C:\windows\temp\$Msi`" $Params")	
    				} else {
    					Write-Warning "The directory $Dir on $Computer is not available"
    			} else {
    				Write-Warning "$Computer is offline"

    Usage: InstallMsi.ps1 -IpFilePath 'C:\ips.txt' -MsiFilePath 'C:\MSIs\msi1.msi','C:\MSI\msi2.msi','C:\MSI\msi3.msi' -Params 'REBOOT=REALLYSUPPRESS' -Verbose

  • #16738

    H Man

    just a heads up ur missing the ] and you have an extra } at the end


  • #16759


    Thanks Adam, I was wondering is there a way to have the script ask for IP addresses and which file to load?

  • #16760

    Adam Bertram

    Execute the script like this: Usage: InstallMsi.ps1 -IpFilePath 'C:\ips.txt' -MsiFilePath 'C:\MSIs\msi1.msi','C:\MSI\msi2.msi','C:\MSI\msi3.msi' -Params 'REBOOT=REALLYSUPPRESS' -Verbose

    Replace C:\ips.txt with your text file with IPs in it.

You must be logged in to reply to this topic.