locked
Start-Job and Invoke-Command jobs running as ps v1? RRS feed

  • Question

  • Any way I can force the background jobs to run as my current powershell version (v5.1).  This outputs the same with Invoke-Command -AsJob as well.  I think I'm missing something stupid.

    start-job -ScriptBlock {Get-host | Select-Object Version}

    Receive-Job -id 286 Version RunspaceId ------- ---------- 1.0.0.0 6b69377d-5156-4708-8273-e9f34ed4e7af


    Thursday, February 21, 2019 8:51 PM

Answers

  • PS D:\scripts> start-job -ScriptBlock {$PsVersionTable} | Receive-job -Wait
    
    Name                           Value
    ----                           -----
    PSRemotingProtocolVersion      2.3
    BuildVersion                   10.0.17763.316
    PSVersion                      5.1.17763.316
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    PSEdition                      Desktop
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    SerializationVersion           1.1.0.1
    
    
    PS D:\scripts>
    You have to ask the right question.

    \_(ツ)_/


    • Edited by jrv Thursday, February 21, 2019 9:12 PM
    • Marked as answer by aacajo Thursday, February 21, 2019 10:11 PM
    Thursday, February 21, 2019 9:11 PM

All replies

  • PS D:\scripts> start-job -ScriptBlock {$PsVersionTable} | Receive-job -Wait
    
    Name                           Value
    ----                           -----
    PSRemotingProtocolVersion      2.3
    BuildVersion                   10.0.17763.316
    PSVersion                      5.1.17763.316
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    PSEdition                      Desktop
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    SerializationVersion           1.1.0.1
    
    
    PS D:\scripts>
    You have to ask the right question.

    \_(ツ)_/


    • Edited by jrv Thursday, February 21, 2019 9:12 PM
    • Marked as answer by aacajo Thursday, February 21, 2019 10:11 PM
    Thursday, February 21, 2019 9:11 PM
  • Ah ok.  I'm trying to call another script that has this block in it and it triggers the echo.

    if ((get-host).Version.Major -lt "4") {
      echo "[!] Need PowerShell v4 or later"
      exit 1
    }

    Not running the right check then?

    Thursday, February 21, 2019 9:36 PM
  • Use:

    #required -Version 4

    as the first line of your script.  It will prompt that V4 is needed.


    \_(ツ)_/

    Thursday, February 21, 2019 10:10 PM
  • Also:

    $PSVersionTable.PSVersion -lt 4.0.0.0

    or this:

    $PSVersionTable.PSVersion.Major -lt 4


    \_(ツ)_/



    • Edited by jrv Thursday, February 21, 2019 10:13 PM
    Thursday, February 21, 2019 10:12 PM