Jump to content

Powershell script to wait until called script is finished


Recommended Posts

Posted

Hi All,

 

hopefully an easy one;

 

I have a CMD prompt that calls a powershell script, but I need the CMD promt to remain open until the powershell is finished it's job -

 

Is it a simple case of adding something like -wait at the end?

 

PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""[script location].ps1""' -Verb RunAs}"
Posted
Why are you launching powershell to launch powershell again? Running just the line in the square brackets should keep cmd open until it's completed.

 

It's a legacy command to change the execution policy (I think, some time has passed since I last used this script)

 

Long story short MDT likes CMD lines, but not powershell, hence a CMD to launch a PS1..... confusing right?

 

So you think

Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""[script location].ps1""' -Verb RunAs

 

Will achieve the wait time when launched from CMd prompt?

Posted
It's a legacy command to change the execution policy (I think, some time has passed since I last used this script)

 

Long story short MDT likes CMD lines, but not powershell, hence a CMD to launch a PS1..... confusing right?

 

So you think

 

 

Will achieve the wait time when launched from CMd prompt?

 

Your cmd launches powershell, which launches powershell. Launching the powershell directly should make cmd wait for the powershell to exit.

  • Thanks 1
Posted
PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""[script location].ps1""' -Verb RunAs

 

I'll give it a try, thanks

 

Ok, the final command was:

 

PowerShell.exe -NoProfile -ExecutionPolicy Bypass -File "[script_location].ps1"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...