Question

Adding additional functions to an MSI install

  • 20 September 2022
  • 3 replies
  • 242 views

Badge

Hello.  What I’m trying to do is install an application.  Then once it is installed, create 2 folders and then create and modify a configuration file and put it into the last layer folder.  The MSI installs with my parameters.  If I manually create my subfolders, the PS script will create my file with configurations.  It seems to be tripping up with creating the folders.  Below is my script.  I hope someone can see what I did wrong and help me to get it to work.  

 

exit (Start-Process -FilePath 'msiexec.exe' -ArgumentList ('/qn', '/i', '"splunkforwarder-8.2.8-da25d08d5d3e-x64-release.msi" LAUNCHSPLUNK=0 AGREETOLICENSE=Yes GENRANDOMPASSWORD=1 INSTALLDIR="c:\Program Files\SplunkUniversalForwarder" SERVICESTARTTYPE=auto /quiet') -Wait -Passthru).Endscript

# Pause 1 minutes
Start-Sleep -Seconds 60
# Make 2 Directories
New-Item "c:\Program Files\SplunkUniversalForwarder\etc\apps" -Name "ks_all_deploymentclient" -ItemType "directory"
New-Item "c:\Program Files\SplunkUniversalForwarder\etc\apps\ks_all_deploymentclient" -Name "local" -ItemType "directory"
# Create the file
New-Item "c:\program files\SplunkUniversalForwarder\etc\apps\ks_all_deploymentclient\local\deploymentclient.conf"
Set-Content -Path "c:\program files\SplunkUniversalForwarder\etc\apps\ks_all_deploymentclient\local\deploymentclient.conf" '[deployment-client]
# Set the phoneHome at the end of the PS engagement
# 10 minutes
# phoneHomeIntervalInSecs = 600
[target-broker:deploymentServer]
# Change the targetUri
targetUri = splunk-deployment.domain.com:8089' 
 


3 replies

Userlevel 5
Badge +1

@Ussmak looks like the script is set to exit after the first step. I’d remove “exit” from that first line. replace with a variable if you want to use it later on.  

$install = (Start-Process -FilePath 'msiexec.exe' -ArgumentList ('/qn', '/i', '"splunkforwarder-8.2.8-da25d08d5d3e-x64-release.msi" LAUNCHSPLUNK=0 AGREETOLICENSE=Yes GENRANDOMPASSWORD=1 INSTALLDIR="c:\Program Files\SplunkUniversalForwarder" SERVICESTARTTYPE=auto /quiet') -Wait -Passthru).Endscript

 

For fun with exit codes I’d look into using:

$LastExitCode is the return code of native applications.

OR

$? just returns True or False

Badge

Hi Jack,

After I made the change you suggested the install went, but the rest didn’t complete.  I did find that I left out my -Path tag after each New-Item.  Once I popped those in, the whole thing worked they way I wanted it to!  Thanks for your help!!

Userlevel 5
Badge +1

Glad you figured it out @Ussmak

I’ve started the habit of building all scripts that will be put into Automox by using psexec and 32-bit Powershell ISE. 

This replicates how Automox runs code on a Windows OS. The experience is a near match and a great way to spot trouble before running a worklet on Windows.

  1. Download PSExec https://learn.microsoft.com/en-us/sysinternals/downloads/psexec and extract to a directory you will use next
  2. Use this command to open 32-bit PowerShell as SYSTEM
    C:\tools\psexec.exe -s -i -d C:\windows\SysWOW64\WindowsPowerShell\v1.0\powershell_ise.exe

    Here is what it looks like 

     

Reply