# msiexec in Powershell

I am looking to be able to run the following command in a powershell script:
msiexec /i C:\Security\AgentInstall64.msi INSTALLDIR="%PROGRAMFILES%\Manufacturer\Endpoint Agent" ENDPOINTSERVER="10.10.10.10" TOOLS_KEY="xyz" UNINSTALLPASSWORDKEY="xyz" SERVICENAME="EDPA" WATCHDOGNAME="WDP" ARPSYSTEMCOMPONENT="1" ENDPOINT_CERTIFICATE="C:\Security\endpoint_cert.pem" ENDPOINT_PRIVATEKEY="C:\Security\endpoint_priv.pem" ENDPOINT_PRIVATEKEY_PASSWORD="xyz" ENDPOINT_TRUSTSTORE="C:\Security\endpoint_truststore.pem" LOGDETAILS="Yes" /L*v %SystemDrive%\installAgent.log
LVL 1
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

QA Engineer IIICommented:
0
Author Commented:
I can run it in a .bat script, but need to run in powershell.
0
QA Engineer IIICommented:
Execute the following command to configure your PC to run local scripts (files not downloaded from the Internet).
Set-ExecutionPolicy RemoteSigned
In a powershell window, run your script
agentInstall
0
Commented:
It's not so easy to accomplish because of all the spaces, " characters and environment vars used in the commandline.
But you can do it with the call operator (&) like this:

$varProgramFiles = [Environment]::GetEnvironmentVariable("ProgramFiles","Process")$varSystemDrive = [Environment]::GetEnvironmentVariable("SystemDrive","Process")

$strCommand = "msiexec.exe"$env:strArguments = @('/i C:\Security\AgentInstall64.msi', "INSTALLDIR=""${varProgramFiles}\Manufacturer\Endpoint Agent""",  'ENDPOINTSERVER="10.10.10.10"', 'TOOLS_KEY="xyz"', 'UNINSTALLPASSWORDKEY="xyz"', 'SERVICENAME="EDPA"', 'WATCHDOGNAME="WDP"',  'ARPSYSTEMCOMPONENT="1"', 'ENDPOINT_CERTIFICATE="C:\Security\endpoint_cert.pem"', 'ENDPOINT_PRIVATEKEY="C:\Security\endpoint_priv.pem"',  'ENDPOINT_PRIVATEKEY_PASSWORD="xyz"', 'ENDPOINT_TRUSTSTORE="C:\Security\endpoint_truststore.pem"', 'LOGDETAILS="Yes"', "/L*v${varSystemDrive}\installAgent.log")

& $strCommand %strArguments% 0 Author Commented: Doesnt work still get the msiexec.exe prompt. 0 Commented: Would it be able to post a screenshot of the command and error message ? Are you maybe using special characters in the passwords ? Can you also try the following:$varProgramFiles = [Environment]::GetEnvironmentVariable("ProgramFiles","Process")
$varSystemDrive = [Environment]::GetEnvironmentVariable("SystemDrive","Process")$strCommand = "c:\windows\system32\cmd.exe"
$env:strArguments = @('/i C:\Security\AgentInstall64.msi', "INSTALLDIR=""${varProgramFiles}\Manufacturer\Endpoint Agent""",
'ENDPOINTSERVER="10.10.10.10"', 'TOOLS_KEY="xyz"', 'UNINSTALLPASSWORDKEY="xyz"', 'SERVICENAME="EDPA"', 'WATCHDOGNAME="WDP"', 
'ARPSYSTEMCOMPONENT="1"', 'ENDPOINT_CERTIFICATE="C:\Security\endpoint_cert.pem"', 'ENDPOINT_PRIVATEKEY="C:\Security\endpoint_priv.pem"',
'ENDPOINT_PRIVATEKEY_PASSWORD="xyz"', 'ENDPOINT_TRUSTSTORE="C:\Security\endpoint_truststore.pem"', 'LOGDETAILS="Yes"', "/L*v ${varSystemDrive}\installAgent.log") &$strCommand /c msiexec.exe %strArguments%
0
Author Commented:
Decided on using .bat instead of .ps1 due to issues executing the command.
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
That's a pity to hear. In my testing I compared the command with the info from your question and it does look exactly the same.
0
Author Commented:
I appreciate the assistance with trying to troubleshoot. Thank you zalazar.
0
Author Commented:
Closing Ticket due to time constraints and alternate solution with .bat
0
Commented:
Good luck with the .bat and you're welcome.
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.