Hello All,

I don’t use powershell much and i am trying to get more familiar with it. I am currently working on a script that needs to install a an agent that communicates to an internal URL. I am trying to make it a silent install and only want the user to see the start and end of the installation. I’ve tried the below variations and they don’t seem to work. Anyone have any simple script they use to do installs or tell me what i am doing wrong on the below syntax?

start-Process “\testpath\msipath\program.msi” /i /qn http://testserver

Error message – Start-Process : A positional parameter cannot be found that accepts argument ‘/qn’.
At line:1 char:1

  • Start-Process "path\ …
  • CategoryInfo : InvalidArgument: (:slight_smile: [Start-Process], ParameterBindingException
  • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand

2nd script –

Process process = new Process();
process.StartInfo.FileName = “msiexec.exe”;
process.StartInfo.Arguments = string.Format(“/qn /i "{0}" ALLUSERS=1”,“\testpath\msipath\program.msi”-InternalURL http://testserver) ;
process.Start();
process.WaitForExit();
Error message

At line:1 char:8

  • Process process = new Process();
  • ~
    Missing statement block after ‘process’.
    At line:1 char:16
  • Process process = new Process();
  • ~
    Missing statement block after ‘process’.
    At line:1 char:9
  • Process process = new Process();

Script command clause ‘process’ has already been defined.
At line:1 char:17

  • Process process = new Process();
  • ~
    Unexpected token ‘=’ in expression or statement.
  • CategoryInfo : ParserError: (:slight_smile: , ParentContainsErrorRecordException
  • FullyQualifiedErrorId : MissingNamedStatementBlock
5 Spice ups
.\testpath\testpath\testpath\test.msi

That will probably work.

1 Spice up

How about this?

Invoke-Expression ".\testpath\msipath\program.msi /i /qn http://testserver"

This assumes the folder path is relative to the directory you are running this from.Edit: I didn’t actually try this, but I’m pretty sure start-process is the wrong command.

1 Spice up

With Start-Process I am pretty sure you have to do something like this

Start-Process -FilePath "$env:systemroot\system32\msiexec.exe" -ArgumentList "/i `"<path\to\installer.msi>`" /qn"

edit- added “>” to end path.

4 Spice ups

Here you go , with a bonus feature of waiting until it is installed!

#Install Microsoft SQL Server System CLR Types package 
$InstallMSI= $SourceRoot+"3rdParty\MS Report Viewer Runtime\SQLSysClrTypes.msi"
msiexec /i $InstallMSI /q
Write-Output "Installing MS Report Viewer Runtime SQLSysClrTypes"
#Wait untill MSI Installer is done  
$StartInstallDate = (Get-Date)
$SucessfullInstall = $Null
do
{
    $SucessfullInstall = get-eventlog -logname application -after $StartInstallDate -Source "MSIInstaller" | where {$_.eventID -eq 11707} 
    Start-Sleep -Seconds 60
    Write-host "Waiting until $InstallMSI is installed"   
}
until ($SucessfullInstall)
2 Spice ups

Close, you need to add commas between each argument in -ArgumentList and each argument must be encapsulated in quotes. For this example, something like this:

Start-Process -FilePath "$env:systemroot\system32\msiexec.exe" -ArgumentList "/i `"<path\to\installer.msi>`"" , "/qn" -Wait

I like to throw in a -Wait just in case you have other things in the script you need to do after the msi is done installing.

Here is an example that I have used and I know works for installing Kaspersky using their msi files:

$KNALocalPath =  "C:\Temp\KNATemp\exec\Kaspersky Network Agent.msi"
$KESLocalPath = "C:\Temp\KESTemp\exec\Kes10win.msi"
$KNAArgs = "/qn", "INSTALLDIR=C:\KasperskyNetworkAgent"
$KESArguments = "/qn"

Start-Process -FilePath "$KNALocalPath" -ArgumentList $KNAArgs -Wait
Start-Process -FilePath "$KESLocalPath" -ArgumentList $KESArguments -Wait
1 Spice up

You also might want to copy the files directly to the target machine depending on the size. It makes it a bit easier since you don’t need UNC paths (which can be tricky with spaces and all that). Here is the whole script I use for Kaspersky.

if (!(Test-Path C:\Temp))
    {
        New-Item -ItemType Directory -Path C:\temp
    }

Copy-Item \\server\Packages\NetAgent\ -Recurse -Destination C:\Temp\KNATemp
Copy-Item \\server\Packages\KES_10.2.4.674\ -Recurse -Destination C:\Temp\KESTemp

$KNALocalPath =  "C:\Temp\KNATemp\exec\Kaspersky Network Agent.msi"
$KESLocalPath = "C:\Temp\KESTemp\exec\Kes10win.msi"
$KNAArgs = "/qn", "INSTALLDIR=C:\KasperskyNetworkAgent"
$KESArguments = "/qn"

Start-Process -FilePath "$KNALocalPath" -ArgumentList $KNAArgs -Wait
Start-Process -FilePath "$KESLocalPath" -ArgumentList $KESArguments -Wait

Sleep 10

Remove-Item C:\Temp\KNATemp -Recurse
Remove-Item C:\Temp\KESTemp -Recurse

It copies the files locally, runs the first MSI and the second one will start only after the first has finished. Then a 10 second wait just in case. Then cleaning up the files at the end.