Using -AsJob

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 1 week, 4 days ago.

  • Author
    Posts
  • #76776

    Paul H.
    Participant

    I'm having a problem using this command.

    Why does this work:

    $csjob = get-wmiobject win32_computersystem -comp file-01 -asjob

    ...but this fails:

    $csjob = get-eventlog system -comp file-01 -asjob

    Get-EventLog : A parameter cannot be found that matches parameter name 'asjob'.
    At line:1 char:44
    + $csjob = get-eventlog system -comp file-01 -asjob
    + ~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Get-EventLog], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetEventLogCommand

  • #76779

    Don Jones
    Keymaster

    Because Get-EventLog doesn't have an -AsJob parameter, just as the error indicates.

    Get-WmiObject's possession of -AsJob is actually something of a weird artifact. The replacement command, Get-CimInstance, doesn't.

    You're meant to use Invoke-Command in all cases.

    Invoke-Command -Script { Get-EventLog System -Comp file-01 } -AsJob
    

You must be logged in to reply to this topic.