Warwick_Tech Posted December 13, 2019 Posted December 13, 2019 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}"
Warwick_Tech Posted December 17, 2019 Author Posted December 17, 2019 Forgive my ignorance; Where would that sit in relation to the code?
bald_pig Posted December 17, 2019 Posted December 17, 2019 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.
Warwick_Tech Posted December 17, 2019 Author Posted December 17, 2019 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?
bald_pig Posted December 17, 2019 Posted December 17, 2019 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. 1
bald_pig Posted December 17, 2019 Posted December 17, 2019 Ooh, I'd drop the "start-process" at the start
Warwick_Tech Posted December 17, 2019 Author Posted December 17, 2019 PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""[script location].ps1""' -Verb RunAs I'll give it a try, thanks
Warwick_Tech Posted December 20, 2019 Author Posted December 20, 2019 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"
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now