简体   繁体   English

Invoke-Command AsJob参数设置不起作用

[英]Invoke-Command AsJob parameter set not working

I am able to do 我能做

Invoke-Command -ScriptBlock { Z:\\prog.bat }

However, when I do 但是,当我这样做

Invoke-Command -ScriptBlock { Z:\\prog.bat } -AsJob

I keep getting 我不断

Invoke-Command : Parameter set cannot be resolved using the specified named parameters. At line:1 char:1 + Invoke-Command -ScriptBlock { z:\\prog.bat } - ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindingException + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand

My intention is to run Z:\\Prog.bat in the background since I will be executing this thru Ansible 我的意图是在后台运行Z:\\ Prog.bat,因为我将通过Ansible执行此操作

Per the comments, this error message is telling you that it's not possible for PowerShell to know which Parameter Set you are trying to use. 根据注释,此错误消息告诉您PowerShell无法知道您要使用哪个参数集。 A Parameter Set is a collection of Parameters that are used together, some mandatory and some optional. 参数集是一起使用的参数的集合,一些必需参数和一些可选参数。 Some cmdlets have a single set, some cmdlets have different combinations allowing them to be used in different ways. 一些cmdlet具有单个集合,某些cmdlet具有不同的组合,从而允许以不同的方式使用它们。

You are using -ScriptBlock and -AsJob . 您正在使用-ScriptBlock-AsJob Invoke-Command has quite a large number of Parameter Sets and to make your call of these parameters unique you need to use them with one of these parameters: Invoke-Command具有大量的参数集,并且要使这些参数的调用唯一,您需要将它们与以下参数之一一起使用:

  • -Session
  • -ComputerName
  • -ConnectionUri
  • -VMId
  • -VMName
  • -ContainerID

Eg: 例如:

Invoke-Command -ScriptBlock { Z:\prog.bat } -AsJob -Computername SomeComputer

Alternatively if you're just attempting to run a script block as a background job on your local machine, don't use Invoke-Command instead consider using Start-Job : 另外,如果您只是尝试在本地计算机上将脚本块作为后台作业运行,请不要使用Invoke-Command而应考虑使用Start-Job

Start-Job { Z:\prog.bat }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM