How to make powershell wait for exe to install?

So, I read every answer related to this question, but none of them seem to work.

These lines go to my script:

$exe = ".\wls1033_oepe111150_win32.exe"
$AllArgs = @('-mode=silent', '-silent_xml=silent_install.xml', '-log=wls_install.log"')
$check = Start-Process $exe $AllArgs -Wait -Verb runAs
$check.WaitForExit()

After that, the regular expression check is performed on the installed files, which replace some specific lines, but no matter what I try to do, it continues to run the regular expression check during the installation of the program.

How can I make sure that the next line is not executed until it finishes installing exe? I also tried connecting to Out-Null without any luck.

+5
source share
1 answer

I created a test executable that executed the following

    Console.WriteLine("In Exe start" + System.DateTime.Now);
    System.Threading.Thread.Sleep(5000);
    Console.WriteLine("In Exe end" + System.DateTime.Now);

powershell script, , , , exe "end of ps1"

push-location "C:\SRC\PowerShell-Wait-For-Exe\bin\Debug";
$exe = "PowerShell-Wait-For-Exe.exe"  
$proc = (Start-Process $exe -PassThru)
$proc | Wait-Process

Write-Host "end of ps1" + (Get-Date).DateTime

exe.

$check = Start-Process $exe $AllArgs -Wait -Verb runas
Write-Host "end of ps1" + (Get-Date).DateTime

WaitForExit .

You cannot call a method on a null-valued expression.
At line:2 char:1
+ $check.WaitForExit()
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

$p = New-Object System.Diagnostics.Process
$pinfo = New-Object System.Diagnostics.ProcessStartInfo("C:\PowerShell-Wait-For-Exe\bin\Debug\PowerShell-Wait-For-Exe.exe","");
$p.StartInfo = $pinfo;
$p.Start();
$p.WaitForExit();
Write-Host "end of ps1" + (Get-Date).DateTime

, , PowerShell Start-Process .NET Framework

+8

All Articles