Invoke-command -parameters

This topic contains 4 replies, has 2 voices, and was last updated by  Jeff Taylor 2 years, 1 month ago.

  • Author
  • #37336

    Jeff Taylor

    Have found two examples of Invoke-Command in PS MOL 2nd ed. where the example includes -parameters that aren't native for the cmdlet. In other words, they don't list out via Intellisense, yet they do work:

    pg 251

    Invoke-Command -command


    pg 252

    Invoke-Command {} -session

    Neither -command nor -session are listed automatically via intellisense. -Command I think is a positional parameter and is not explicitly required however -session IS required if I want to pass my $session content.

    Please help me to understand these particular flavors of parameters.


  • #37340

    Dave Wyatt

    The -Session parameter does exist on Invoke-Command, so you should be seeing it in intellisense. -Command, on the other hand, was renamed to -ScriptBlock later on, to be more consistent with other similar cmdlets such as Start-Job and Register-ObjectEvent, etc. There is still a -Command alias for -ScriptBlock, for backward compatibility. It'll still tab-complete, but aliases don't show up in Intellisense.

  • #37343

    Jeff Taylor

    "The -Session parameter does exist on Invoke-Command, so you should be seeing it in intellisense"

    I only see "-SessionName" and "-SessionOption" populating via Intellisense and they won't work with an actual session id I have in a variable. I have to use only "-session" (as the book demonstrates)

  • #37354

    Dave Wyatt

    I don't know what to tell you. If I'm in the ise and I type "Invoke-Command -", to start Intellisense, -Session is the very first thing in the list for me.

  • #37389

    Jeff Taylor

    I was able to repro the issue:

    The example in the book uses a {} scriptblock *before* the parameter switch. So, yes, if I simply omit the script block I do get intellisense to populate the simple -session parameter.

    What prompted my initial question is the example as illustrated in the book.

You must be logged in to reply to this topic.