powershell - Get-Job by State and Name? -
powershell v3.
start-job -name "testjob" -scriptblock { write-host "foo" } the job starts fine. type
get-job and see
id name psjobtypename state hasmoredata location command -- ---- ------------- ----- ----------- -------- ------- 18 testjob backgroundjob completed true localhost write-host "foo" everything going according plan far. let's have many jobs running in session, , have various different names. want find jobs named testjob:
get-job -name testjob this works expected, returning jobs of name. let's want find jobs both have name testjob and still running:
ps c:\> get-job -name testjob -state running get-job : parameter set cannot resolved using specified named parameters. @ line:1 char:1 + get-job -name testjob -state running + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : invalidargument: (:) [get-job], parameterbindingexception + fullyqualifiederrorid : ambiguousparameterset,microsoft.powershell.commands.getjobcommand is there way this?
try following
get-job -state completed | where-object {$_.name.contains("testjob")} here's sample run based on example
ps d:\> get-job -state completed | where-object {$_.name.contains("job")} id name state hasmoredata location command -- ---- ----- ----------- -------- ------- 1 testjob completed true localhost write-host "foo" 3 testjob completed true localhost write-host "foo" see get-help where-object more info on this.
Comments
Post a Comment