I am testing a few domains and their ability to alert me when an abnormal event happens. I am using nmap to scan domains for open ports. The script below opens a new cmd window and runs nmap. I search for the process ID and checks to see if the process(cmd) is still running. Once the scan is over, it will run the nmap scan again.
function nmaptest {
$prog1="cmd"
$params1=@("/C";"nmap.exe -Pn -sX 192.168.1.0/24")
Start-Process -Verb runas $prog1 $params1 #starts
}
while(1 -eq 1){
nmaptest
$processes = get-process $prog1 | out-string
$sp = $processes.Split(' ',[System.StringSplitOptions]::RemoveEmptyEntries)
$procid = $sp[22]
echo $procid
while(get-process -id $procid){ }
}
This works fine. What I need help with is doing this process 8 times in parallel. (if that is possible)