Wait for Process
Jump to navigation
Jump to search
About
Powershell function to wait until the required program launches before continuing the install process.
Function
#region Function Wait-ForProcess Function Wait-ForProcess { <# .SYNOPSIS Waits until the required program launches before continuing the install process. Example: Wait-ForProcess -Name notepad -IgnoreAlreadyRunningProcesses .DESCRIPTION .PARAMETER .LINK http://psadt.com/ #> Param ( $Name = 'notepad', [Switch] $IgnoreAlreadyRunningProcesses ) Begin { { If ($IgnoreAlreadyRunningProcesses) { $NumberOfProcesses = (Get-Process -Name $Name -ErrorAction SilentlyContinue).Count } Else { $NumberOfProcesses = 0 } Write-Log -Message "Waiting for $Name...." -LogType 'CMTrace' -LogFileDirectory $appLogPath -LogFileName $appLogFile While ((Get-Process -Name $Name -ErrorAction SilentlyContinue).Count -eq $NumberOfProcesses) { Sleep 5 } } } } #endregion