Jul*_*lia 6 powershell scripting
我正在尝试运行一个脚本,该脚本将运行另一个 powershell 脚本。我需要第一个脚本在另一个脚本结束后才能继续。就像是:
启动 Copy.ps1 等到 Copy.ps1 完成
继续执行脚本
尝试使用 Invoke-Expression 但它没有等待参数。
我认为您可以通过像这样调用文件来轻松做到这一点:
<#
here is some awesome code
#>
# Call P$ Script here
& C:\Path\To\CopyScript.ps1
<#
awesome code continues here
#>
Run Code Online (Sandbox Code Playgroud)
它将调用 Copy.ps1 中的整个脚本,并在 copy.ps1 完成后继续。
另一种方法是将 copy.ps1 中的整个脚本设置为一个函数。
在 CopyScript.ps1 中:
function MyCopyFunction(){
# all code inside the Copy.ps1 is here
}
Run Code Online (Sandbox Code Playgroud)
在你的新文件中:
# Call P$ Script here
& C:\Path\To\CopyScript.ps1
# then call the function
MyCopyFunction
Run Code Online (Sandbox Code Playgroud)
格雷茨·埃尔多 (Greetz Eldo)
| 归档时间: |
|
| 查看次数: |
16854 次 |
| 最近记录: |