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
# Change the targetUri
targetUri = splunk-deployment.domain.com:8089'
For fun with exit codes I’d look into using:
$LastExitCodeis the return code of native applications.
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!!
Glad you figured it out
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.
Here is what it looks like