Using -AsJob

Welcome Forums General PowerShell Q&A Using -AsJob

This topic contains 1 reply, has 2 voices, and was last updated by

2 years, 1 month ago.

  • Author
  • #76776

    Topics: 1
    Replies: 0
    Points: 2
    Rank: Member

    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

    Topics: 13
    Replies: 4872
    Points: 1,843
    Helping HandTeam Member
    Rank: Community Hero

    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

The topic ‘Using -AsJob’ is closed to new replies.