是否有可能调用PowerShell命令异步? [英] Is it possible to call powershell cmdlets asynchronously?

查看:388
本文介绍了是否有可能调用PowerShell命令异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有cmdlet1和cmdlet2,都是长时间运行的任务。通常我会拥有它调用了两个cmdlet为了一个批处理文件:

 通话PowerShell的cmdlet1
打电话的PowerShell cmdlet2

反正是有设置它们赶走异步?


解决方案

如果你在PowerShell中2,您可以使用后台作业。

从帮助:


  

参阅about_Jobs


  
  

    

当你启动一个后台作业,将返回命令提示符
    立即,
        即使该作业需要较长的时间来完成。您可以继续
        在本届会议的工作不会中断,而作业运行。


  

所以,你可以使用

 启动工作-ScriptBlock {} cmdlet1
启动工作-ScriptBlock {} cmdlet2

不过,你需要有PowerShell的配置远程处理,在本地运行的作业也是如此。

我也绊了这一点:

Say i have cmdlet1 and cmdlet2, both are long running tasks. Normally i would have a batch file which calls the two cmdlets in order:

call powershell cmdlet1
call powershell cmdlet2

Is there anyway to set them off asynchronously?

解决方案

If you're on PowerShell 2, you can use background jobs.

From the help:

about_Jobs

When you start a background job, the command prompt returns immediately, even if the job takes an extended time to complete. You can continue to work in the session without interruption while the job runs.

So you can use

Start-Job -ScriptBlock { cmdlet1 }
Start-Job -ScriptBlock { cmdlet2 }

However, you need to have PowerShell configured for remoting, even when running a job locally.

I also stumbled over this:

这篇关于是否有可能调用PowerShell命令异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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