I have a script that uses Start-Process with the -Wait switch within a foreach loop. When I run this script in PowerShell V2 mode with PowerShell Studio, it 'waits' properly. When I run it in PowerShell V3 mode within PowerShell Studio, it doesn't wait.
However, when I run the very same script from a standalone PowerShell v3 console (outside of PowerShell Studio), it waits as expected.
I have Windows 7 Enterprise SP1 32-bit and PowerShell Studio 2012 3.1.23.
The code is similar to as follows:
PowerShell Code
Double-click the code block to select all.foreach ($IP in $UniqueData) { $p++ Write-Progress -Activity "Checking IPs" -Status "Percent completed: " -PercentComplete (($p / $UniqueData.Count) * 100) $error.clear() $DataLine = "" | Select-Object IP, Hostname, OS, Site, AccessPermittedPrimary, AccessPermittedSecondary, InAD, DNSServer1, DNSServer2, DNSServer3, DNSServer4, DNSServer5, DNSServer6, NeedsChange, Changed if (Test-Connection -ComputerName $IP -Count 1 -Quiet){ # Machine pings $RandomNumber = Get-Random -Minimum 0 -Maximum 50000 $NmapFile = "C:\Temp\Output" + $RandomNumber + ".xml" Start-Process -FilePath C:\Users\Me\Desktop\nmap-6.40\nmap.exe -ArgumentList "$IP -Pn -O -n -oX $NmapFile" -WindowStyle 'Hidden' -Wait $var = parse-nmap $NmapFile $OS = $var.OS Remove-Item $NmapFile }I know it's not waiting for the process to exit because it's trying to remove the file that hasn't been created or saved by the process yet (generates errors).