0

I'm trying to write a script in PowerShell that will search a folder for a specific msi file (subfolder location will vary) and then run an install command referencing that file and other files that would be in the same directory. It would be for a tool that our L1 helpdesk staff could use to run an install for software assigned through SCCM, possibly using different command line variables than what SCCM would run.

Tried different combinations of code and can't install the app.

This works fine on finding the software

Get-ChildItem -Path C:\Windows\ccmcache -Recurse -Filter softwarename.msi

ForEach portion does not work

$Path = Get-ChildItem -Path C:\Windows\CCMCache -Recurse -Filter Something.MSI

ForEach ( $Installer in ( Get-ChildItem -Path $Path.DirectoryName -Filter *.MSI ) ) {

Start-Process -Wait -FilePath C:\windows\system32\msiexec.exe -ArgumentList "/i $Installer.FullName"
}

I basically want to do something like this, using the directory the msi file was found in to do the install:

msiexec /i softwarename.msi /q /norestart

1 Answers1

2

The only thing I see wrong is you can't normally refer to properties of an object inside of a string without adding $( ):

Start-Process -Wait -FilePath C:\windows\system32\msiexec.exe -ArgumentList "/i $($Installer.FullName)"

Why not run msiexec directly?

msiexec /i $installer.fullname
js2010
  • 23,033
  • 6
  • 64
  • 66