CoreePower.Lib.System.Process.ps1
<#
.SYNOPSIS Starts a new process without creating a visible window. .DESCRIPTION The Start-ProcessSilent function starts a new process with the specified file and arguments, and captures both the standard output and standard error streams. This function is designed to be used with applications that normally create a visible window, and suppresses the window from appearing on the desktop. .PARAMETER File The path to the file to be executed. .PARAMETER Arguments The arguments to be passed to the file. .EXAMPLE PS C:\> $output, $errorOutput = Start-ProcessSilent -File "$((Get-Command "cmd.exe").Path)" -Arguments "/C dir" Starts the specified file with the specified arguments, and captures both the standard output and standard error streams. #> function Start-ProcessSilent { param( [Parameter(Mandatory=$true)] [string]$File, [Parameter(Mandatory=$false)] [string]$Arguments = "" ) $psi = New-Object System.Diagnostics.ProcessStartInfo $psi.FileName = $File $psi.Arguments = $Arguments $psi.WorkingDirectory = [System.IO.Path]::GetDirectoryName($File) $psi.CreateNoWindow = $true $psi.UseShellExecute = $false $psi.RedirectStandardOutput = $true $psi.RedirectStandardError = $true $process = [System.Diagnostics.Process]::Start($psi) $output = $process.StandardOutput.ReadToEnd() $errorOutput = $process.StandardError.ReadToEnd() $process.WaitForExit() return ,$output, $errorOutput } |