title: Powershell wait and release
body: <p>My script is somewhat complete, but I would like to add some handling of processes in it:</p>
  
  <pre><code>#Call Bluezone to do file transfer
  &amp; "C:\Program Files (x86)\BlueZone FTP\6.1\Bzftpf.exe" /F"ccaihfs.zft"
  #Variable Declarations
  $source = "\\fhnsrv01\home\aborgetti\Documentation\Stage\"
  $dest = "\\fhnsrv01\home\aborgetti\Documentation\Stage\orig"
  $archive = "\\fhnsrv01\home\aborgetti\Documentation\Stage\archive"
  
  #First copy the original file to the orig folder before any manipulation takes place
  Copy-item $source\*.EDIPROD $dest
  # Now we must rename the items that are in the folder
  Switch(GCI \\fhnsrv01\home\aborgetti\Documentation\Stage\*.EDIPROD){
      {(GC $_|Select -first 1).substring(176) -match "^834"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"834Dailyin$($Matches[1]).txt"};Continue}
      {(GC $_|Select -first 1).substring(176) -match "^820"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"820Dailyin$($Matches[1]).txt"};Continue}
      {(GC $_|Select -first 1) -match "NO INPUT"}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName {"NOINPUTin$($Matches[1]).txt"};Continue}
      {(GC $_|Select -first 1) -match ""}{$_ | ?{$_.Name -match "^.+?\.D(\d{6}).*"} | Rename-Item -NewName Default {"Could not find 834 or 820 qualifier in file $_"};Continue}
  }
  #move files older than 1 month to archive
  $date = (get-date).AddDays(-31)
  GCI \\fhnsrv01\home\aborgetti\Documentation\Stage\*.txt| Where{$_.CreationTime -lt (get-date).adddays(-31)}| move-item -destination $archive
  </code></pre>
  
  <p>This works splendid as is, the only problem is this line:</p>
  
  <pre><code>&amp; "C:\Program Files (x86)\BlueZone FTP\6.1\Bzftpf.exe" /F"ccaihfs.zft"
  </code></pre>
  
  <p>It's calling an FTP program. The problem is this process takes awhile. The results get manipulated with the rest of the script. But powershell is so fast that it just does what it has to do before the file transfer is complete.</p>
  
  <p>I have some auto-config options set in the FTP program so that it auto closes after the file transfers are complete. This should release the PID/mem of that program.</p>
  
  <p>I know PS can handle this scenario. Just don't know how.</p>
  
  <p>I think what I want to do is put PS on hold until this is done processing and then when it releases the PID, finish up the script.</p>