# Help with understating WaitForExit() role

**URL:** <https://forums.powershell.org/t/help-with-understating-waitforexit-role/16935>\
**Category:** PowerShell Help\
**Created:** [June 28, 2021, 8:13am UTC](https://forums.powershell.org/t/help-with-understating-waitforexit-role/16935 "2021-06-28T08:13:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![arielma](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@arielma](https://forums.powershell.org/u/arielma)\
**Post date:** [June 28, 2021, 8:13am UTC](https://forums.powershell.org/t/help-with-understating-waitforexit-role/16935/1 "2021-06-28T08:13:37Z")

</div>

Hi  
I have the below code:

```auto
$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
$sqlpackageDeploy.WaitForExit()
$sqlpackageDeploy

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:

```auto
$sqlpackageDeploy.WaitForExit()
$sqlpackageDeploy

```

or I can remove these lines?

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [June 28, 2021, 7:58pm UTC](https://forums.powershell.org/t/help-with-understating-waitforexit-role/16935/2 "2021-06-28T19:58:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![arielma](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@arielma](https://forums.powershell.org/u/arielma)\
**Post date:** [June 29, 2021, 3:16pm UTC](https://forums.powershell.org/t/help-with-understating-waitforexit-role/16935/3 "2021-06-29T15:16:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [June 29, 2021, 4:27pm UTC](https://forums.powershell.org/t/help-with-understating-waitforexit-role/16935/4 "2021-06-29T16:27:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:23pm UTC](https://forums.powershell.org/t/help-with-understating-waitforexit-role/16935/5 "2024-05-16T20:23:57Z")

</div>


