you can get the Process object or ID using the get-process command to get the process object, or you can get it as shown below, or it will work.
you can use PID and call
$proc = [System.Diagnostics.Process]::GetProcessById($PID) while(-not $proc.HasExited) {[System.Threading.thread]::sleep(500) }
source share