4
votes

I downloaded Powerbi 32 bit and 64 bit msi files from https://powerbi.microsoft.com/en-us/downloads/

and created below script .

$ScriptDir = (Split-Path $MyInvocation.MyCommand.Path)


$MSIArguments = @(
    "/i"
    "$ScriptDir\PBIDesktop.msi"
    "/qn"
 #   "/norestart"
     "ACCEPT_EULA=1"
)

$MSIArguments2 = @(
    "/i"
    "$ScriptDir\PBIDesktop_x64.msi"
    "/qn"
#    "/norestart"
    "ACCEPT_EULA=1"
)

$architecture=gwmi win32_processor | select -first 1 | select addresswidth
if ($architecture.addresswidth -eq "64"){
    Start-Process "msiexec.exe" -ArgumentList $MSIArguments2 -wait
}
elseif ($architecture.addresswidth -eq "32"){
   Start-Process "msiexec.exe" -ArgumentList $MSIArguments -wait
    }
$ScriptDir

Script works perfectly only if the source directory/$ScriptDir does not have spaces in between. for example if source directory is c:/test or c:/test_test/test it works perfectly.

But if the source directory/$ScriptDir has spaces, it hangs with msi option error given below

enter image description here

for example if source directory/$ScriptDir is C:\Users\Dell\Desktop\New folder powershell script hangs at above message .. yet no installation .

i have added echo at the end of the script to find the path $ScriptDir

and it gives below echo result which makes me more confusing.

    C:\Users\Dell\Desktop\New folder

Not sure why msiexec.exe cant run arguments when there is a space .

Please help me to fiugre out What could be the reason ? how could this be fixed to run even if $ScriptDir is having spaces ?

1

1 Answers

3
votes

If you were to call msiexec.exe (or most other commands) from the command line with a path with spaces in it, you'd need to wrap that path in quotes.

Unfortunately, your path by the time it's being passed through doesn't actually have them (despite supplying them in your hash table.)

To do this, provide some escaped quotes (""):

$MSIArguments = @(
    "/i"
    """$ScriptDir\PBIDesktop.msi"""
    "/qn"
 #   "/norestart"
     "ACCEPT_EULA=1"
)

This has the practical end result of: for paths, wrap them in three quote marks.