Isaias Perez
Isaias Perez

Reputation: 25

MSIExec via Powershell Install

Find the list of MSI Files from a directory and install on given PC remotely or locally . I want to be able to to run a script that will install 8 separate MSI files in a given directory 1 by 1. I found this script and think it work but i feel as if it is missing something right?

foreach($_msiFiles in 
($_msiFiles = Get-ChildItem $_Source -Recurse | Where{$_.Extension -eq ".msi"} |
 Where-Object {!($_.psiscontainter)} | Select-Object -ExpandProperty FullName)) 
{
    msiexec /i $_msiFiles /passive
} 

Upvotes: 1

Views: 196

Answers (1)

m0lochwalker
m0lochwalker

Reputation: 432

It would help you to understand what is going on here. I would write it something like this:

Declare source Directory:

$source = “\\path\to\source\folder”

Put each child .msi object into an array:

$msiFiles = Get-Childitem $source -File -recurse | Where-Object {$_.Extension -eq “.msi”}

Iterate the array to run each .msi:

Foreach ($msi in $msiFiles) {

Msiexec /I “$($msi.FullName)” /passive

}

This is of course just an explanation of what you are doing. It does not include any error handling, checking for return codes, or remote command syntax, etc. etc.

Upvotes: 1

Related Questions