locked
[pscustomobject] to pipeline not working RRS feed

  • Question

  • Hello,

    I'm trying to understed how psobject working. I have something like this

    $obj = [pscustomobject]@{Identity='SRV01';IPAddress='192.168.1.10'}

    So now I'm trying to pipe it to Get-ADComputer:

    $obj | Get-ADComputer -identity $_.Identity


    But i'm getting following error:

    Get-ADComputer : The input object cannot be bound to any parameters for the command either because the command does not take pipeline
    input or the input and its properties do not match any of the parameters that take pipeline input.

    The same thing if I'm trying:

    $obj | Test-Netconnection -IPAddress $_.IPAddress

    Do you know why it isn't working? I just want to pass one object to another cmdlet. It working when:

    Get-ADComputer -identity $obj.identity

    But passing to pipline does not work.


    • Edited by XTECH_netPS Friday, October 26, 2018 9:38 AM
    Friday, October 26, 2018 9:35 AM

Answers

  • Use help to check parameters.  "Identity" is not a pipeline parameter by name.

    To pipeline an object we don't use the syntax you are using.

    $obj = [pscustomobject]@{
        Identity = 'SRV01'
        IPAddress = '192.168.1.10'
    }
    $obj | 
        ForEach-Object{
            Get-ADComputer $_.Identity
        }
    # IPAddress is a pipeline variable by name
    $obj | Test-Connection


    \_(ツ)_/




    • Edited by jrv Friday, October 26, 2018 9:56 AM
    • Marked as answer by XTECH_netPS Friday, October 26, 2018 9:58 AM
    Friday, October 26, 2018 9:54 AM

All replies

  • Use help to check parameters.  "Identity" is not a pipeline parameter by name.

    To pipeline an object we don't use the syntax you are using.

    $obj = [pscustomobject]@{
        Identity = 'SRV01'
        IPAddress = '192.168.1.10'
    }
    $obj | 
        ForEach-Object{
            Get-ADComputer $_.Identity
        }
    # IPAddress is a pipeline variable by name
    $obj | Test-Connection


    \_(ツ)_/




    • Edited by jrv Friday, October 26, 2018 9:56 AM
    • Marked as answer by XTECH_netPS Friday, October 26, 2018 9:58 AM
    Friday, October 26, 2018 9:54 AM
  • Identity can be piped by value though.

    'SRV01' | Get-ADComputer

    or

    $obj.Identity | Get-ADComputer


    Multiple servers:

    'SRV01','SRV02','SRV03' | Get-ADComputer

    • Edited by JS2010 Saturday, October 27, 2018 12:41 PM
    Friday, October 26, 2018 12:27 PM