SOLVED

PowersShell script to install a msi with custom parameters

Copper Contributor

Hi !

It's my first post in the community hoping to find a solution for this. I am using a script to install an msi that is being pulled from a cloud download location and using powershell to parse the parameters while installing the msi. I'm using the following script. It downloads the msi successfully but when trying to run the install will show the Windows Installer windows. Are the brackets i've set correct? I'm relatively new to PowerShell so any help is highly appreciated!

Thank you,

 

#file to download

$DownloadURL ="https://cdn-104.anonfiles.xxxmsi"
#location to save on the computer. Path must exist or it will error
$DOwnloadPath = "C:\Okta\xxxxx.msi"

#for
$ArgumentsMSI ='/I' + '" ' + "$DOwnloadPath" + '" " ' + ' SITEURL=xxx SELECTED_xx_ENVIRONMENT=xxxcom ADMIN_xx_EDITBOX_VALUE=xxx;IS_ENCRYPTED=0 LOGOFILE=xxx SSPR_URL=xxx SSO_ENABLED=0 PASSWORD_SYNC_ENABLED=1 TECUNIFY_CHECKBOX_STATE=0 UPS_ENABLED=0 UTM_ENABLED=0 LOCALUSER=1 DOMAINUSER=1 MICROSOFTUSER=1 AZUREUSER=1 PKPENABLE=xx OFFLINE_ENABLED=1 FAILOPEN=0 OFFLINE_MAX_TRIES_LIMIT=5 SELECTED_UAC_OPTION=1 CONTACT_INFO= xxx

 

$MSI = 'true'


#downloads the file from the URL
wget $DownloadURL -outfile $DOwnloadPath

if($MSI -eq 'true')
{
#Install MSI
Write-Host $ArgumentsMSI
write-host "Starting Install"
Start-Process -FilePath "msiexec.exe" -Wait -ArgumentList $ArgumentsMSI

}

 


exit 0

 

Beu52265_0-1641507377211.png

 

5 Replies
best response confirmed by Beu5-2265 (Copper Contributor)
Solution

Regardless of method to generate the space delimited string of parameters, output the string to see that it is what you want. I'd step back and do something like this first, read the output string carefully. I took a stab at shuffling some single, doublequote, and spaces, and pulled out one semicolon but don't know if that is right. Also added /qn for Quiet, No GUI.

Quotes around the msi file name might help if the actual path you have there has spaces in it.

 

It dumps out this now

 

 

$ArgumentsMSI
/i ".\xxxxx.msi" /qn SITEURL=xxx SELECTED_xx_ENVIRONMENT=xxxcom ADMIN_xx_EDITBOX_VALUE=xxx IS_ENCRYPTED=0 LOGOFILE=xxx SSPR_URL=xxx SSO_ENABLED=0 PASSWORD_SYNC_ENABLED=1 TECUNIFY_CHECKBOX_STATE=0 UPS_ENABLED=0 UTM_ENABLED=0 LOCALUSER=1 DOMAINUSER=1 MICROSOFTUSER=1 AZUREUSER=1 PKPENABLE=xx OFFLINE_ENABLED=1 FAILOPEN=0 OFFLINE_MAX_TRIES_LIMIT=5 SELECTED_UAC_OPTION=1 CONTACT_INFO=xxx

 

 

code (if it lets me post this time)

 

$DownloadPath = ".\xxxxx.msi"

$ArgumentsMSI ='/i ' + '"' + "$DownloadPath" + '" ' + '/qn ' + 'SITEURL=xxx SELECTED_xx_ENVIRONMENT=xxxcom ADMIN_xx_EDITBOX_VALUE=xxx IS_ENCRYPTED=0 LOGOFILE=xxx SSPR_URL=xxx SSO_ENABLED=0 PASSWORD_SYNC_ENABLED=1 TECUNIFY_CHECKBOX_STATE=0 UPS_ENABLED=0 UTM_ENABLED=0 LOCALUSER=1 DOMAINUSER=1 MICROSOFTUSER=1 AZUREUSER=1 PKPENABLE=xx OFFLINE_ENABLED=1 FAILOPEN=0 OFFLINE_MAX_TRIES_LIMIT=5 SELECTED_UAC_OPTION=1 CONTACT_INFO=xxx'

'Output arguments and verify first'
Write-Host $ArgumentsMSI

'Only run after verifying output of resulting $ArgumentsMSI first'
'Start-Process -FilePath "msiexec.exe" -Wait -ArgumentList $ArgumentsMSI'

 

 

 

 

 

Hi Karl,

I really appreciate the follow up. I did manage to execute the msi through a few tests, you help was greatly appreciated. The only thing i'm having issues is to parse the parameters now. It does work on the first one, but the rest of them get added to the same box when i run the installer with a gui to test. Sorry for the size of the image, hopefully you can zoom in. I will add the code to make sure we're on the same page. Should the +  be added after each parameter? I tried and all went in the same parameter box value.  Seems like it requires the single quotes to parse. 

Beu52265_2-1641996334025.png

 

$DOwnloadPath = "C:\ProgramData\Temp\xxx.msi"
$ArgumentsMSI = '/i' + '"' + $DOwnloadPath + '" ' + 'SITEURL=xx' + 'SELECTED_xxx_ENVIRONMENT=xx.com' + 'ADMIN_SECRET_CA_DATA="ADMINSECRET=xx;IS_ENCRYPTED="'
"LOGOFILE=xxx'
'SSPR_URL= xxx'
'SSO_ENABLED=0'
'PASSWORD_SYNC_ENABLED=1'
'TECUNIFY_CHECKBOX_STATE=0"
'UPS_ENABLED=0'
'UTM_ENABLED=0'
'LOCALUSER=1'
'DOMAINUSER=1'
'MICROSOFTUSER=1'
'AZUREUSER=1'
'PKPENABLE=0'
'OFFLINE_ENABLED=1'
'FAILOPEN=0'
'OFFLINE_MAX_TRIES_LIMIT=5'
'SELECTED_UAC_OPTION=1'
'CONTACT_INFO= xxx'

@Karl Fasick 

@Beu5-2265 

from your screenshot of your code it appear that you have them on separate lines (or is this just word wrap turned on in your editor?) - if you want to spilt a variable across multiple lines you need to include a space after the last character and the ` on each line except for the last last so PowerShell treats it as one line

 

Hi Steve,
Thanks for the advice provided. Seemed that it was correct as in the beginning. Only the parameters needed a test manually to make sure they're parsing the strings correctly. It's all set now, finally got it to work.

Thanks guys!
The -argumentList parameter of start-process accepts an array of arguments too. You could have had each argument as an array item. Like so:
$argumentsMSI = “arg1”, “arg2”, “arg3”
1 best response

Accepted Solutions
best response confirmed by Beu5-2265 (Copper Contributor)
Solution

Regardless of method to generate the space delimited string of parameters, output the string to see that it is what you want. I'd step back and do something like this first, read the output string carefully. I took a stab at shuffling some single, doublequote, and spaces, and pulled out one semicolon but don't know if that is right. Also added /qn for Quiet, No GUI.

Quotes around the msi file name might help if the actual path you have there has spaces in it.

 

It dumps out this now

 

 

$ArgumentsMSI
/i ".\xxxxx.msi" /qn SITEURL=xxx SELECTED_xx_ENVIRONMENT=xxxcom ADMIN_xx_EDITBOX_VALUE=xxx IS_ENCRYPTED=0 LOGOFILE=xxx SSPR_URL=xxx SSO_ENABLED=0 PASSWORD_SYNC_ENABLED=1 TECUNIFY_CHECKBOX_STATE=0 UPS_ENABLED=0 UTM_ENABLED=0 LOCALUSER=1 DOMAINUSER=1 MICROSOFTUSER=1 AZUREUSER=1 PKPENABLE=xx OFFLINE_ENABLED=1 FAILOPEN=0 OFFLINE_MAX_TRIES_LIMIT=5 SELECTED_UAC_OPTION=1 CONTACT_INFO=xxx

 

 

code (if it lets me post this time)

 

$DownloadPath = ".\xxxxx.msi"

$ArgumentsMSI ='/i ' + '"' + "$DownloadPath" + '" ' + '/qn ' + 'SITEURL=xxx SELECTED_xx_ENVIRONMENT=xxxcom ADMIN_xx_EDITBOX_VALUE=xxx IS_ENCRYPTED=0 LOGOFILE=xxx SSPR_URL=xxx SSO_ENABLED=0 PASSWORD_SYNC_ENABLED=1 TECUNIFY_CHECKBOX_STATE=0 UPS_ENABLED=0 UTM_ENABLED=0 LOCALUSER=1 DOMAINUSER=1 MICROSOFTUSER=1 AZUREUSER=1 PKPENABLE=xx OFFLINE_ENABLED=1 FAILOPEN=0 OFFLINE_MAX_TRIES_LIMIT=5 SELECTED_UAC_OPTION=1 CONTACT_INFO=xxx'

'Output arguments and verify first'
Write-Host $ArgumentsMSI

'Only run after verifying output of resulting $ArgumentsMSI first'
'Start-Process -FilePath "msiexec.exe" -Wait -ArgumentList $ArgumentsMSI'

 

 

 

 

View solution in original post