Powershell script to run another powershell script and wait till over

我是研究僧i 提交于 2019-12-23 17:48:21

问题


i'm trying to run a script which will run another powershell script. i need the first script to continue only after the other one is over. something like:

start Copy.ps1 wait till Copy.ps1 is done
continue with the script

tried using the Invoke-Expression but it doesn't have wait parameter.


回答1:


I think you easily can do it by calling the file like this:

<#
  here is some awesome code
#>

// Call P$ Script here
.("C:\Path\To\Copy.ps1")

<#
  awesome code continues here
#>

it will call the whole script in Copy.ps1 and continues after copy.ps1 finished.

Other method is you set the whole script in copy.ps1 into a function.

in Copy.ps1:

function MyCopyFunction(){

  // all code inside the Copy.ps1 is here

}

And in your new File:

// Call P$ Script here
.("C:\Path\To\Copy.ps1")

//then call the function
MyCopyFunction

Greetz Eldo.Ob




回答2:


From https://community.idera.com/database-tools/powershell/ask_the_experts/f/learn_powershell_from_don_jones-24/19166/wait-for-powershell-script-to-complete-before-starting-another-script

You can just put an ampersand in front of the script name, e.g.

& .\Copy.ps1


来源:https://stackoverflow.com/questions/40237306/powershell-script-to-run-another-powershell-script-and-wait-till-over

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!