用于运行另一个 PowerShell 脚本并等待结束的 Powershell 脚本 [英] Powershell script to run another powershell script and wait till over

查看:106
本文介绍了用于运行另一个 PowerShell 脚本并等待结束的 Powershell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个脚本,该脚本将运行另一个 powershell 脚本.我需要第一个脚本在另一个脚本结束后才能继续.类似:

开始复制.ps1等到 Copy.ps1 完成
继续脚本

尝试使用 Invoke-Expression 但它没有等待参数.

解决方案

我认为您可以通过像这样调用文件来轻松完成:

<预><代码><#这是一些很棒的代码#>//在这里调用 P$ 脚本.("C:\Path\To\Copy.ps1")<#很棒的代码在这里继续#>

它将调用 Copy.ps1 中的整个脚本并在 copy.ps1 完成后继续.

另一种方法是将 copy.ps1 中的整个脚本设置为一个函数.

在 Copy.ps1 中:

function MyCopyFunction(){//Copy.ps1 中的所有代码都在这里}

在你的新文件中:

//此处调用 P$ 脚本.("C:\Path\To\Copy.ps1")//然后调用函数我的复制功能

Greetz Eldo.Ob

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.

解决方案

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

这篇关于用于运行另一个 PowerShell 脚本并等待结束的 Powershell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆