PS Month of Lunches 2nd ed; CH 20 Sessions; (get-pssession and -comp wildcards)

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 8 months, 1 week ago.

  • Author
    Posts
  • #37274
    Profile photo of Jeff Taylor
    Jeff Taylor
    Participant

    I was running the example on pg 252:

    Invoke-Command -command {Get-CimInstance -class win32_process } -Session (Get-PSSession -ComputerName loc*)

    and get error:
    Get-PSSession : Invalid URI: The hostname could not be parsed.

    Digging deeper I ran: Get-PSSession -ComputerName *

    and get: Get-PSSession : Missing an argument for parameter 'ComputerName'. Specify a parameter of type 'System.String[]' and try again.

    then tried: Get-PSSession -ComputerName localhost and THAT worked.

    So, tried the wildcard again: Get-PSSession -ComputerName loc*
    and get same error: "...Invalid URI: The hostname could not be parsed."

    What's up with -ComputerName wild cards as used in the book?

  • #37276
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    The -ComputerName parameter doesn't accept wildcards. Not sure if that's a change from a previous version. Personally, I don't use Get-PSSession at all. When I use New-PSSession, I assign the results to a variable, and a use that variable later on:

    $session = New-PSSession -ComputerName localhost
    
    Invoke-Command -Session $session { Do-Stuff }
    

You must be logged in to reply to this topic.