SOLVED

PowersShell script to install a msi with custom parameters

%3CLINGO-SUB%20id%3D%22lingo-sub-3053842%22%20slang%3D%22en-US%22%3EPowersShell%20script%20to%20install%20a%20msi%20with%20custom%20parameters%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3053842%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20!%3C%2FP%3E%3CP%3EIt's%20my%20first%20post%20in%20the%20community%20hoping%20to%20find%20a%20solution%20for%20this.%20I%20am%20using%20a%20script%20to%20install%20an%20msi%20that%20is%20being%20pulled%20from%20a%20cloud%20download%20location%20and%20using%20powershell%20to%20parse%20the%20parameters%20while%20installing%20the%20msi.%20I'm%20using%20the%20following%20script.%20It%20downloads%20the%20msi%20successfully%20but%20when%20trying%20to%20run%20the%20install%20will%20show%20the%20Windows%20Installer%20windows.%20Are%20the%20brackets%20i've%20set%20correct%3F%20I'm%20relatively%20new%20to%20PowerShell%20so%20any%20help%20is%20highly%20appreciated!%3C%2FP%3E%3CP%3EThank%20you%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23file%20to%20download%3C%2FP%3E%3CP%3E%24DownloadURL%20%3D%22%3CA%20href%3D%22https%3A%2F%2Fcdn-104.anonfiles.xxxmsi%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fcdn-104.anonfiles.xxxmsi%3C%2FA%3E%22%3CBR%20%2F%3E%23location%20to%20save%20on%20the%20computer.%20Path%20must%20exist%20or%20it%20will%20error%3CBR%20%2F%3E%24DOwnloadPath%20%3D%20%22C%3A%5COkta%5Cxxxxx.msi%22%3C%2FP%3E%3CP%3E%3CSPAN%3E%23for%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%24ArgumentsMSI%20%3D'%2FI'%20%2B%20'%22%20'%20%2B%20%22%24DOwnloadPath%22%20%2B%20'%22%20%22%20'%20%2B%20'%20SITEURL%3Dxxx%20SELECTED_xx_ENVIRONMENT%3Dxxxcom%20ADMIN_xx_EDITBOX_VALUE%3Dxxx%3BIS_ENCRYPTED%3D0%20LOGOFILE%3Dxxx%20SSPR_URL%3Dxxx%20SSO_ENABLED%3D0%20PASSWORD_SYNC_ENABLED%3D1%20TECUNIFY_CHECKBOX_STATE%3D0%20UPS_ENABLED%3D0%20UTM_ENABLED%3D0%20LOCALUSER%3D1%20DOMAINUSER%3D1%20MICROSOFTUSER%3D1%20AZUREUSER%3D1%20PKPENABLE%3Dxx%20OFFLINE_ENABLED%3D1%20FAILOPEN%3D0%20OFFLINE_MAX_TRIES_LIMIT%3D5%20SELECTED_UAC_OPTION%3D1%20CONTACT_INFO%3D%20xxx%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24MSI%20%3D%20'true'%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%23downloads%20the%20file%20from%20the%20URL%3CBR%20%2F%3Ewget%20%24DownloadURL%20-outfile%20%24DOwnloadPath%3C%2FP%3E%3CP%3Eif(%24MSI%20-eq%20'true')%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%23Install%20MSI%3CBR%20%2F%3EWrite-Host%20%24ArgumentsMSI%3CBR%20%2F%3Ewrite-host%20%22Starting%20Install%22%3CBR%20%2F%3EStart-Process%20-FilePath%20%22msiexec.exe%22%20-Wait%20-ArgumentList%20%24ArgumentsMSI%3CBR%20%2F%3E%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3Eexit%200%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Beu52265_0-1641507377211.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Beu52265_0-1641507377211.png%22%20style%3D%22width%3A%20387px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F337826i6BDBEACD4D3145D4%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Beu52265_0-1641507377211.png%22%20alt%3D%22Beu52265_0-1641507377211.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3053842%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New 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 (New 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”