0

I want to run multiple commands at once with pause and but I'm not sure how. Here's my current code:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
ipconfig /registerdns
ipconfig /flushdns

Regards

I did try it with Start-Sleep, I don't get any solution.

3
  • 2
    "at once with pause" sounds a bit self-contradicting. What is the problem with the code you already have, and what exact difference in behavior are you looking for? Commented Jul 1, 2024 at 9:13
  • I really not sure I can run the all 3 commands without pause or at the same time, because the ipconfig /registerdns need maybe 20 10 second Commented Jul 1, 2024 at 9:40
  • 1
    Each command will wait for the previous command to finish. Commented Jul 1, 2024 at 15:47

1 Answer 1

0

If I understand your question, you would like to run multiple processes but force the previous to complete its process before allowing the next to run.

If this is the case then start-process should be able to help with this utilizing the -wait parameter, you can also hide the process window using the parameter -windowstyle with the value hidden.

You would use -filepath parameter to specify the the application and then use the -argumentlist for any arguments you want to pass through to that application:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Start-Process -FilePath C:\Windows\System32\ipconfig.exe -ArgumentList "/registerdns" -wait -WindowStyle hidden

Start-Process -FilePath C:\Windows\System32\ipconfig.exe -ArgumentList "/flushdns" -wait -WindowStyle hidden
Sign up to request clarification or add additional context in comments.

2 Comments

yes, I want to have first process is finished until the second process will be begin. I did run your command, it appear a CMD windows with "Windows IP Configuration", can I hide that command Window?
@Kourosh, I have added the parameter to hide the command prompt when executing IPConfig. If this has helped please upvote the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.