Pipeline Parameter by PropertyName

Welcome Forums General PowerShell Q&A Pipeline Parameter by PropertyName

This topic contains 8 replies, has 4 voices, and was last updated by

js
 
Participant
3 months, 3 weeks ago.

  • Author
    Posts
  • #110033

    Participant
    Points: 5
    Rank: Member

    I must be doing something wrong.  Hopefully someone can help.  When I try to pass the -computername parameter for Get-HotFix it only returns the local machine, but works when I use it in paranthesis for the parameter.  BTW, this is from a Month of Lunches Lab (chapter 9).  According to the help for Get-Hotfix, the computername parameter should work as pipeline input by PropertyName.

     

    get-adcomputer -filter * | select @{n='computername';e={$_.name}} | Get-HotFix
    #This only returns objects for the domain controller (local machine)
    
    Get-HotFix -ComputerName (select -ExpandProperty name)
    #This works and returns objects for all the computers on the domain

     

     

  • #110044

    Participant
    Points: 894
    Helping Hand
    Rank: Major Contributor

    Are you sure on

    
    
    
  • #110045
    js

    Participant
    Points: 327
    Helping Hand
    Rank: Contributor

    Looks like a bug. I can't get the second method to work either.

  • #110047

    Participant
    Points: 894
    Helping Hand
    Rank: Major Contributor

    Are you sure on

    Get-HotFix -ComputerName (select -ExpandProperty name)
  • #110048

    Participant
    Points: 5
    Rank: Member

    My bad I'm working from an offline lab environment so I can't copy and paste.  The second line that works is this:

    Get-HotFix -ComputerName (get-adcomputer -filter * | select -ExpandProperty name)

    I'm using PSVersion 4.0 and Server 2012 with activedirectory module imported.

  • #110060

    Participant
    Points: 894
    Helping Hand
    Rank: Major Contributor

    -ComputerName parameter in Get-HotFix takes value from pipeline only in documentation, Actually it doesn't.
    It just iterates through the list of computers specified to ComputerName.

    The parameter is just defined like ValueFromPipelineByPropertyName = true

    yourself can check it from the source code here. It doesn't even have a ProcessRecord() method.

    just filed an issue on it.

  • #110035

    Participant
    Points: 1
    Rank: Member

    I'm kinda new to PowerShell but in line one if you are passing a variable "computername" it should have a $ in front and also in double quotes "" instead of single quotes to allow it to use what is stored.

     

    Hope this helps.

    • #110087
      js

      Participant
      Points: 327
      Helping Hand
      Rank: Contributor

      That's actually right. It's a hash table to make a custom property with select-object.

      PS C:\users\superuser> get-process chrome | select-object @{n='myname';e={$_.name}}
      
      myname
      ------
      chrome

The topic ‘Pipeline Parameter by PropertyName’ is closed to new replies.