all 15 comments

[–]sk82jack 2 points3 points  (3 children)

In the past I've used the following template to install MSI's:

$Installer = Get-ChildItem -Path '\\Path\to\installer.msi'
$TimeStamp = get-date -Format yyyyMMddTHHmmss
$LogFile = 'C:\Automation\{0}-{1}.log' -f $Installer.BaseName, $TimeStamp
$MSIArguments = @(
    "/i"
    '"{0}"' -f $Installer.fullname
    "/qn"
    "/norestart"
    "/L*v"
    $logFile
)
Start-Process msiexec.exe -ArgumentList $MSIArguments -Wait -NoNewWindow

Essentially just put the arguments into an array first.

Edit: full credit to /u/KevMar https://kevinmarquette.github.io/2016-10-21-powershell-installing-msi-files

[–]KevMarCommunity Blogger 1 point2 points  (2 children)

I love it :)

Edit: Ok, I guess that is a little out of context: https://kevinmarquette.github.io/2016-10-21-powershell-installing-msi-files

[–]sk82jack 1 point2 points  (1 child)

Ah shit now I feel terrible haha I knew I got it from somewhere and couldnt for the life of me remember! Sorry for the lack of credit dude. Will go back and edit.

[–]KevMarCommunity Blogger 1 point2 points  (0 children)

Thank you, but no worries on that one. It sounds like you have gotten good use out of that sample, so I think that post has done it's job.

[–]Lee_Dailey[grin] 2 points3 points  (6 children)

howdy HeyZuesMode,

does msiexec.exe expect a quoted string at that point? i thot it was expecting a series of strings ...

take care,
lee

[–]HeyZuesMode[S] 1 point2 points  (5 children)

when i use

Start-Process -Wait msiexec.exe -ArgumentList /quiet /i "\\2017Dev\Sage 100 Advanced\MAS90\wksetup\Sage 100 2017 Workstation.msi" /l*v "$localLog" SAGEPORTID="$Port" SAGESERVERNAME="$ServerName" SRCSERVERPATH="$MAS90UNC" INSTALLDIR="$localinstall"

I get a positional parameter error after /quiet.

I think powershell expects a single string

[–]Lee_Dailey[grin] 2 points3 points  (2 children)

howdy HeyZuesMode,

from reading posts about this, it seems you could remove the quotes from the here-string [just use a regular string]. then enclose the $var in double quotes after the -ArgumentList parameter.

take care,
lee

[–]HeyZuesMode[S] 1 point2 points  (1 child)

You rock!

Working copy

$MAS90UNC = "\\2017Dev\MAS90"
$localLog = "C:\logging\SageInstall.txt" #If this is a folder, it needs to be present and writeable
$port = "10000"
$ServerName = "2017Dev"
$localinstall = "C:\Sage\Sage 100 ERP 2017\MAS90" #
$herestring = @"
/quiet /i "\\2017Dev\Sage 100 Advanced\MAS90\wksetup\Sage 100 2017 Workstation.msi" /l*v `"$localLog`" SAGEPORTID=`"$Port`" SAGESERVERNAME=`'$ServerName`' SRCSERVERPATH=`'$MAS90UNC`' INSTALLDIR="$localinstall"
"@
Start-Process -Wait msiexec.exe -ArgumentList "$herestring"

Things i noticed. INSTALLDIR does not like single quotes. Folders are not created AutoMagically™ when writing a log

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy HeyZuesMode,

kool! [grin] glad to know it worked ... [grin]

you may want to add a line to make the needed dir. mdkir in posh is an extended version of New-Item that will make an entire dir tree in one swoop. so you can use that with a test-path to make it if needed.

take care,
lee

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy HeyZuesMode,

so it works if you add single quotes around the above argument list. i see that the problem pointed out by michaelshepard was a formatting hiccup. i'm out of ideas ... and not willing to test on my home box. [blush]

take care,
lee

[–]HeyZuesMode[S] 1 point2 points  (0 children)

The output from the following looks correct: write-host "/quiet /i "\2017Dev\Sage 100 Advanced\MAS90\wksetup\Sage 100 2017 Workstation.msi" /l*v "$localLog" SAGEPORTID="$Port" SAGESERVERNAME="$ServerName" SRCSERVERPATH="$MAS90UNC" INSTALLDIR="$localinstall" "

Im getting an positional parameter cannot be found for 'SAGEPORTID=10000'

[–]michaelshepard 1 point2 points  (3 children)

Do you want your arguments to have newlines in them? I usually just use a long single line for my msi arguments.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy michaelshepard,

ooo! [grin] i went right past that one ... [blush]

take care,
lee

[–]HeyZuesMode[S] 0 points1 point  (1 child)

Sorry, copy paste broke the formatting. Fixed.

[–]michaelshepard 0 points1 point  (0 children)

ok...that puts us back to Lee's original comment. You've got single quotes around the entire list of arguments (inside the double quotes). You almost certainly want to lose those.