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
m_travisAsked:
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.

Mark BullockQA EngineerCommented:
Can you open powershell as administrator, then run your script?
m_travisAuthor Commented:
I can run it in a .bat script, but need to run in powershell.
Mark BullockQA EngineerCommented:
Run Windows Powershell as administrator.
Execute the following command to configure your PC to run local scripts (files not downloaded from the Internet).
Set-ExecutionPolicy RemoteSigned

Open in new window

Run Notepad, copy and paste your command, then save as agentInstall.ps1
In a powershell window, run your script
agentInstall

Open in new window

Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

zalazarCommented:
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%

Open in new window

m_travisAuthor Commented:
Doesnt work still get the msiexec.exe prompt.
zalazarCommented:
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%

Open in new window

m_travisAuthor Commented:
Decided on using .bat instead of .ps1 due to issues executing the command.

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
zalazarCommented:
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.
m_travisAuthor Commented:
I appreciate the assistance with trying to troubleshoot. Thank you zalazar.
m_travisAuthor Commented:
Closing Ticket due to time constraints and alternate solution with .bat
zalazarCommented:
Good luck with the .bat and you're welcome.
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.