I want to start a setup.exe with one install parameter => /download example.xml
When I tpye in "C:\Temp\folder\setup.exe /download example.xml" in Windows Explorer Address Bar the setup.exe starts correctly.
How do I do that with Powershell?
I've tried the following:
$setup="C:\Temp\folder\setup.exe "
$Argument = "/download example.xml"
Start-Process $setup -ArgumentList $Argument
What am I doing wrong?
Thanks!
I think it wants a list of arguments. This might do the job
$setup="C:\Temp\folder\setup.exe "
$ArgumentLst = #("/download example.xml")
Start-Process $setup -ArgumentList $ArgumentLst
Related
Here i trying to install MSI package with argument in powershell where i have to pass few special characters as below:
$msi="/I mypkg.msi TARGETAPPPOOL='.NET v4.5 Classic' /L mai.log /qn"
Start-process "msiexec.exe" -ArgumentList $msi -wait -nonewwindow -PassThru
Showing "1639" error code - A command line option passed to the installer is invalid.
Installation working well with default value, if I remove "TARGETAPPPOOL='.NET v4.5 Classic'”
Can you please suggest how we can write it?
Thanks
Pass the arguments as an array like this:
$msi = '/I', 'mypkg.msi', 'TARGETAPPPOOL=".NET v4.5 Classic"', '/L', 'mai.log', '/qn'
Start-process "msiexec.exe" -ArgumentList $msi -wait -nonewwindow -PassThru
PowerShell automatically adds space separator between the arguments.
I have 2 scripts:
Launch.ps1
Deploy.ps1
Launch simply runs deploy as administrator:
clear
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$scriptPathToRun = "$scriptPath\Deploy.ps1"
Start-Process -Verb runAs PowerShell -ArgumentList '-noexit','-File', $scriptPathToRun
I am trying to pass arguments to aspnet_regiis, I have tried the following:
Start-Process -NoNewWindow "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis" -ArgumentList '–ga', 'domian\serviceAccount'
Start-Process -NoNewWindow "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis" -ArgumentList '–ga domian\serviceAccount'
Start-Process -NoNewWindow "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis" -ArgumentList #('–ga', 'domian\serviceAccount')
& "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis" '–ga domian\serviceAccount'
& "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis" '–ga', 'domian\serviceAccount'
& "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis" #('–ga', 'domian\serviceAccount')
In all these attempts, aspnet_regiis is run but it appears no args are passed to it because the output is just a listing of available aspnet_regiis parameters.
Can someone point out what I'm missing? Thanks.
The simplest answer is probably to just run the command using the call/invocation (&) operator:
& "$env:SystemRoot\Microsoft.Net\Framework64\v4.0.30319\aspnet_regiis" -ga domain\serviceAccount
If you really wanted to use Start-Process, you should be able to write it this way:
Start-Process "$env:SystemRoot\Microsoft.Net\Framework64\v4.0.30319\aspnet_regiis" "-ga","domain\serviceAccount" -NoNewWindow
The first token on that command line is the executable to run (i.e., -FilePath). The -ArgumentList parameter is an array (i.e., "-ga","domain\serviceAccount").
I am new to Powershell and, of course, trying to learn on the fly for a project- No pressure, right! :-)
I am working on a script to run an MSI package in quiet mode, passing it an activation code as an argument, that I have to extract from an XML file.
So far, I have everything working except for getting Start-Process to run the MSI with the arguments being passed in a Variable.
Set-ExecutionPolicy Bypass -Force
[System.Xml.XmlDocument]$XML_Doc = new-object System.Xml.XmlDocument
$XML_Doc.load('c:\myfolder\Configinfo.XML')
$ActivationID = $XML_Doc.CONFIGINFO.SITEINFO.ACTIVATEID
write-host "Activation Id is: $ActivationID"
$InstallString = "`'/I C:\myfolder\myinstaller.msi akey="+'"'+$ActivationID+'"'''
#$InstallString = "`'/I C:\myfolder\myinstaller.msi akey=`"$($ActivationID)`"'"
write-host "$InstallString"'''
Start-Process msiexec.exe -ArgumentList $InstallString -Wait -NoNewWindow
#Start-Process msiexec.exe -ArgumentList '/I C:\myfolder\myinstaller.msi akey="12345678-abcd-1a1b-x9x1-a1b2c3d4e5f6"' -Wait -NoNewWindow
Above is the code I am working with now. The last line that is commented out is an activation string that works.
I have verified that $ActivationID is pulling back the correct value, and that $InstallString mirrors the argument list in the commented version of the Start-Process string.
Any help would be appreciated!
The Start-Process commands aren't necessary. PowerShell is a shell. It can run commands. Just put the commands you want to run directly in the script.
msiexec /i "C:\myfolder\myinstaller.msi" "AKEY=$ActivationID"
I quoted the parameters to msiexec.exe in case any of them contain spaces. PowerShell will automatically expand the $ActivationID variable into the string inside the double quotes.
Your ArgumentList is being passed incorrectly.
[Xml]$XML_Doc = Get-Content -Path 'C:\myfolder\Configinfo.xml'
$ActivationID = $XML_Doc.CONFIGINFO.SITEINFO.ACTIVATEID
Write-Host "Activation Id is: $ActivationID"
$Path = 'msiexec'
$ArgList = #('/i','"C:\path\file.msi"',"akey=`"$ActivationID`"")
Write-Host "$Path $ArgList"
Start-Process -FilePath $Path -ArgumentList $ArgList -Wait -NoNewWindow
First off, let me welcome you to Powershell! It's a great language and a great community gathered around a common cause.
Since you're new to the language, you can still learn new tricks and that's a good thing, because it's generally accepted that the Write-Host cmdlet is nearly always a poor choice. If you don't trust me, you should trust the inventor of Powershell.
Now that that's out of the way, we should look at your MSI command. With Powershell, we don't have to directly open msiexec, and we can call the MSI directly. I would break the path to the installer into its own variable, and then we can add all of our arguments on top of it. Also, don't forget the "/qn" switch which will actually make all of this silent. All in all, your new script will look something like this:
[System.Xml.XmlDocument]$XML_Doc = new-object System.Xml.XmlDocument
$XML_Doc.load('c:\myfolder\Configinfo.XML')
$ActivationID = $XML_Doc.CONFIGINFO.SITEINFO.ACTIVATEID
Write-Verbose "Activation Id is: $ActivationID"
$msipath = "C:\myfolder\myinstaller.msi"
$args = #("akey=$ActivationID", "/qn")
Write-Verbose "Install path is $msipath"
Write-Verbose "Activation key is $akey"
Start-Process $msipath -ArgumentList $args -Wait -NoNewWindow
$cs = New-PSSession -ComputerName MACHINE -Credential DOMAIN\admin
Copy-Item -Path C:\Scripts\smart -Destination C:\smart -ToSession $cs
msiexec /i "C:\Smart\SMART.msi" NB_PROD_KEY=NC-2ADA2-F9RKE-AKAIA-BBB ACTIVATE_LICENSE=1 INSTALL_INK="" LAT_CONTENT="" PRINT_CAPTURE="" INSTALL_DOCCAM_DRIVERS="" CUSTOMER_LOGGING=1 /qnT="" INSTALL_SPU=2 CUSTOMER_LOGGING=0 /qn
Hi,
I'm struggling to get the syntax that runs with the MSI working above - I've worked with switches inside script blocks which invoke commands beforfe successfully but, not with those parameters which are from the program vendors help file.
I also tried:
Start-Process "msiexec.exe" -Argumentlist "/i "C:\smartmsi\SMART.msi" `
NB_PROD_KEY=NC-2ADA2-F9RKE-AKAIA-BBB ACTIVATE_LICENSE=1 INSTALL_INK="" LAT_CONTENT="" PRINT_CAPTURE="" INSTALL_DOCCAM_DRIVERS="" CUSTOMER_LOGGING=1 /qn
Totally confused how to install using the vendors commands within POwerShell, how can i nest each argument if it's not a switch?
I also tried using Splatter:
$params = '/i', "C:\smartmsi\SMART.msi",
'NB_PROD_KEY=NC-2ADA2-CEAM7-F9RKE', 'ACTIVATE_LICENSE=1',
'/qn'
& msiexec.exe #params
$LastExitCode
No joy - this app will install remotely as a regular install.
Thanks in advance
UPDATE:
Now, i've also tried this:
invoke-command -Session $session -ScriptBlock {
Start-Process -FilePath C:\windows\system32\msiexec.exe `
-ArgumentList "/i `"C:\smart\SMARTSuite.msi`" `"NB_PROD_KEY=NC-2ADA2`" ACTIVATE_LICENSE=1 INSTALL_INK=`"`" LAT_CONTENT=`"`" PRINT_CAPTURE=`"`" INSTALL_DOCCAM_DRIVERS=`"`" CUSTOMER_LOGGING=1 /qn"
}
Still not working. Installer appears for a second then drops off.
You have to escape `" if you want them to be interpreted inside a string which already uses double quotes else you break the string chaining :
Start-Process -FilePath msiexec -ArgumentList "/i `"C:\smartmsi\SMART.msi`" NB_PROD_KEY=NC-2ADA2-F9RKE-AKAIA-BBB ACTIVATE_LICENSE=1 INSTALL_INK=`"`" LAT_CONTENT=`"`" PRINT_CAPTURE=`"`" INSTALL_DOCCAM_DRIVERS=`"`" CUSTOMER_LOGGING=1 /qn"
You don't have to escape double quotes if the string is surrounded by simple quotes
I'm trying to have the app tablacus explorer open a folder path. This works fine with the following formatting:
$ex = 'S:\Tools\explorer\TE64.exe'
Start-Process $ex -ArgumentList '"Tabs,Close other tabs" "Open,C:\Program Files"'
But I would really like to have the path in a variable ($dir = 'C:\Program Files'), and I can't seem to get the quotes right so it gets interpreted properly.
Thank you for your help.
I found two solutions for this on the MS Blog:
$Args = #"
"Tabs,Close other tabs" "Open,$dir"
"#
start $ex -ArgumentList $Args
or
start $ex -ArgumentList """Tabs,Close other tabs"" ""Open,$dir"""
I found sometimes you need another level of quotes.
In my case, I have to set variables in -Arguments /v, so I had to use \"" to do that.
Start-Process `
-FilePath "Installer.exe" `
-Arguments "/s /qn /v""SOME_PARAM1=\""STRING_IN_PARAM\"" SOME_PARAM2=\""STRING_IN_PARAM\"""
-Wait ;
If your parameters are constant strings then create a shortcut and call that instead.
Set the 'target' of the shortcut to:
"S:\Tools\explorer\TE64.exe" "Tabs,Close other tabs" "Open,C:\Program Files"
Name your shortcut 'TE64' and call it in powershell like this:
start-process S:\Tools\explorer\TE64.lnk
The following syntax works fine for me, try this:
-ArgumentList "\`"$($variable)\`""