Those who were once used to writing batch files will like this tip. In the old days, using the old ways, you could use the Start/Wait command in batch files to cause the script to pause, wait for a process to complete, and then move on to the next steps in the script.

You can do the same thing with PowerShell using the Out-null cmdlet. Out-null actually deletes output instead of routing it to the PowerShell console, so the script will sit and wait for the content to be deleted before moving on.

This will work with practically any process you choose.  Just stick the following at the end of the line (notice the pipe character before the command):

| out-null

To test this out for yourself, create a text file and then use Notepad.exe to open the file:

Notepad.exe myfile.txt | out-null