Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

Hi there

 

I'm trying to create script to install some software. The software supports the CMDLINE=DEFAULT_INSTALL_DIR=

 

$strInstallerFile = C:\Installer\Software.msi

$path = "${env:ProgramFiles(x86)} + \Software"

#$params = '/i ', '$strInstallerFile',' INSTALL_DIR="$path"', "/qn"

Start-Process msiexec.exe -ArgumentList $params -Wait

 

$start = Start-Process msiexec.exe '/i $strInstaller CMDLINE=DEFAULT_INSTALL_DIR="path" /qn'

 

 

 

Can any help or spot what im doing wrong?

 

 

Thanks

Posted (edited)
$strInstallerFile = C:\Installer\Software.msi
$path = "${env:ProgramFiles(x86)} + \Software"
$params = '/i ', [color="#FF0000"]'[/color]$strInstallerFile[color="#FF0000"]'[/color],[color="#FF0000"]'[/color] INSTALL_DIR="$path"[color="#FF0000"]'[/color], "/qn"
Start-Process msiexec.exe -ArgumentList $params -Wait

$start = Start-Process msiexec.exe [color="#FF0000"]'[/color]/i $strInstaller CMDLINE=DEFAULT_INSTALL_DIR="path" /qn[color="#FF0000"]'[/color]

 

Can any help or spot what I'm doing wrong?

There are single quotes around some of your variables (I have highlighted these in red above). This forces PowerShell to treat them as strings.

 

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-6

 

Here are a couple of different ways of scripting it too. :)

 

$Args = '{0} "{1}" {2}"{3}" {4}' -f '/i', "C:\Installer\Software.msi", 'CMDLINE=DEFAULT_INSTALL_DIR=', "${env:ProgramFiles(x86)}\Software", '/qn'

Start-Process -FilePath "msiexec.exe" -ArgumentList $Args -Wait

 

or

 

$Installer = @{
   FilePath = 'msiexec.exe'
   ArgumentList = @(
       '/i',
       'C:\Installer\Software.msi',
       "CMDLINE=DEFAULT_INSTALL_DIR=`"${env:ProgramFiles(x86)}\Software`"",
       '/qn'
   )
   Wait = $True
}
Start-Process @Installer

Edited by Arthur
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...