Invoke-command -parameters

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Jeff Taylor Jeff Taylor 5 months, 3 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #37336
    Profile photo of Jeff Taylor
    Jeff Taylor
    Participant

    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

    and

    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.

    thanks

    #37340
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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
    Profile photo of Jeff Taylor
    Jeff Taylor
    Participant

    "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
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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
    Profile photo of Jeff Taylor
    Jeff Taylor
    Participant

    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.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.