new to powershell - create install script

Hey Guys,

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: (:) [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);
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

Before you even get to the Powershell, have you tried a standard command-line installation?

msiexec /i "C:\testpath\msipath\program.msi" /qb http://testserver

Some basic thing that didn’t look right:

  • The full path the MSI wasn't used. If it's going to be dynamic and you want to reference the installation directory, you can do that, but you should provide a full path to the msi
<li>You say that you want the user to see the installation.  The /qn switch is a silent installation, no interface.  The /qb should be a basic installation interface.</li>
<li>The URL you are passing is a MSI parameter?   There is typically a format like URL="http://testserver".  The MSI parameters are typically named.  That's why I was curious if you actually tested a straight command line before attempting to move to Powershell</li>

With that said, you need to call MSIEXEC, not the MSI. The arguments can be formatted as an array like so and passed. The += is an example of building the array, so you have the option to do if ($something -eq 'blah) {$arguments += “AnotherParam=1”} or something like that. Here is a basic example:

$arguments = @()
$arguments += "/i"
$arguments += "C:\testpath\msipath\program.msi"
$arguments += "/qb"
$arguments += "http://testserver"

(Start-Process -FilePath "msiexec.exe" -ArgumentList $arguments -Wait -PassThru).ExitCode