Help with understating WaitForExit() role

I have the below code:

$StartProcessProps = @{
    FilePath               = 'sqlpackage.exe'
    ArgumentList           = '/Action:Publish /SourceFile:"download\Database Services.dacpac" /TargetConnectionString:"Data Source={0};Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False;Initial catalog={1}" /p:BlockOnPossibleDataLoss={2}' -f $Env, $Target, $Data_loss
    Wait                   = $true
    PassThru               = $true
    Credential             = $cred
    RedirectStandardOutput = 'sqlstdout.txt'
    RedirectStandardError  = 'sqlstderr.txt'
$sqlpackageDeploy = Start-Process @StartProcessProps

if ($sqlpackageDeploy.ExitCode -eq 0) {
     Get-Content sqlstdout.txt
else {
     echo "An error occurred"
     Get-Content sqlstderr.txt
     exit $sqlpackageDeploy.ExitCode

echo "********  End SQL Deploy  ********"

my question is, do I really need to use:


or I can remove these lines?

The parameters already have the Wait = True, not sure you need the WaitForExit(). The next line is just showing the full object returned from Start-Process. Remark them out and try executing the package.

1 Like

So Wait = True is the same as WaitForExit()?

Believe so, you are just telling Start-Process to wait for execution to complete so you can get return codes. Try remarking the lines and testing.