1

I was creating a script of Powershell as a hobby but it can be a tool to be used to install all the files from a given folder after a install from 0. I'm struggling since I don't see where could be the problem. I'm new to PSH but I'm suspicious that it might be a data problem issue:

Start-Process : Este comando no se puede ejecutar debido al error: El sistema no puede encontrar el archivo especificado.

En línea: 47 Carácter: 5

  • Start-Process -FilePath "$installArrayMsi" -ArgumentList '/silent ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
    • FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

The code:

$nameExe=Get-ChildItem | Where-Object -property name -Like "*.exe" | Get-ChildItem -name 
$nameMsi=Get-ChildItem | Where-Object -property name -Like "*.msi" | Get-ChildItem -name
$Location=(Get-Location).path
$Location

$numProgramsExe=$nameExe | Measure-Object -Line | Select-Object -Expand Lines
$numProgramsMsi=$nameMsi | Measure-Object -Line | Select-Object -Expand Lines


$superArrayExe = @($nameExe)

$installArrayExe = @(for ($i = 0; $i -lt $numProgramsExe; $i++)
{ 

    $Location+"\"+$superArrayExe[$i] 
}
)

for ($i = 0; $i -lt $numProgramsExe; $i++)
{ 
    Start-Process -FilePath "$installArrayExe" -ArgumentList '/silent', '/install' -Wait
    Write-Output "Instalando "$superArrayExe[$i]
    Write-Output "   "
}

$superArrayMsi = @($nameMsi)

$installArrayMsi = @(for ($i = 0; $i -lt $numProgramsMsi; $i++)
{ 

    $Location+"\"+$superArrayMsi[$i] 
}
)

for ($i = 0; $i -lt $numProgramsMsi; $i++)
{ 
    Start-Process -FilePath "$installArrayMsi" -ArgumentList '/silent', '/install' -Wait
    Write-Output "Instalando "$superArrayMsi[$i]
    Write-Output "   "
}

3 Answers3

1

I think the trouble comes from the fact that a .msi file is not an executable file but a kind of database. You have to deploy it using the executable file msiexec.exe.

Start-Process "msiexec.exe" -ArgumentList "Your MSI file"

You can try something like

$params = '/i', "$installArrayMsi",
          'INSTALLDIR="$yourInstallDir"', 'ADSK_SETUP_EXE=1',
          '/qb!'
$p = Start-Process 'msiexec.exe' -ArgumentList $params -NoNewWindow -Wait -PassThru
$p.ExitCode
JPBlanc
  • 70,406
  • 17
  • 130
  • 175
1

This is the code that eventually worked well:

$nameMsi=@(Get-ChildItem | Where-Object -property name -Like "*.msi" | Get-ChildItem -name)

$numProgramsMsi=$nameMsi | Measure-Object -Line | Select-Object -Expand Lines

for ($i = 0; $i -lt $numProgramsMsi; $i++)
{ 
    $params = '/i', $nameMsi[$i], '/qb!'
    $params
    $p = Start-Process 'msiexec.exe' -ArgumentList $params -NoNewWindow -Wait -PassThru
    $p.ExitCode
    Write-Output "Instalando "$superArrayMsi[$i]
    Write-Output "   "
}
0

So at the very end I found a better solution for this problem. I hope that it helps to beginners...and installs .Exe!

$nameExe=@(Get-ChildItem | Where-Object {$_.Name -Like "*.exe"})
for ($i = 1; $i -lt $nameExe.Count; $i++)
{ 
    Start-Process -FilePath $nameExe.Name[$i] -ArgumentList '/silent', '/install' -Wait
    Write-Output "Instalando" $nameExe.Name[$i] "`n"
}