在后台作业中调用命令 [英] Invoke-Command in a background job

查看:47
本文介绍了在后台作业中调用命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 powershell 2.0 脚本,它应该在多台服务器上运行一个命令并处理输出.我想在后台作业中为每个服务器运行命令和处理.

I have a powershell 2.0 script which should run a command on several servers and process the output. I want to run the command and the processing for each server in a background job.

命令运行没有任何问题,并在半秒或更短的时间内终止:

The comand works without any problems and terminates within half a second or less:

Invoke-Command -ComputerName $client -ScriptBlock { #do some stuff }

但是当我在后台作业中运行它时,作业不会终止:

But when I run this in a background job, the job doesn't terminate:

Start-Job { Invoke-Command -ComputerName $client -ScriptBlock { #do some stuff } }

有人知道可能是什么问题吗?

Has someone a idea what the problem could be?

推荐答案

看起来你应该换一种方式:

Looks like you should do it the other way:

http://technet.microsoft.com/en-us/library/hh849698.aspx

要在远程计算机上运行后台作业,请使用 AsJob 参数可以在许多 cmdlet 上使用,或者 使用 Invoke-Command cmdlet 来在远程计算机上运行 Start-Job 命令.想要查询更多的信息,请参阅 about_Remote_Jobs.

To run a background job on a remote computer, use the AsJob parameter that is available on many cmdlets, or use the Invoke-Command cmdlet to run a Start-Job command on the remote computer. For more information, see about_Remote_Jobs.

这篇关于在后台作业中调用命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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