# Add-Member : The input object cannot be bound to any parameters

**URL:** <https://forums.powershell.org/t/add-member-the-input-object-cannot-be-bound-to-any-parameters/15620>\
**Category:** PowerShell Help\
**Created:** [February 11, 2021, 4:29am UTC](https://forums.powershell.org/t/add-member-the-input-object-cannot-be-bound-to-any-parameters/15620 "2021-02-11T04:29:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hanskapans](https://avatars.discourse-cdn.com/v4/letter/h/a698b9/32.png) [@hanskapans](https://forums.powershell.org/u/hanskapans)\
**Post date:** [February 11, 2021, 4:29am UTC](https://forums.powershell.org/t/add-member-the-input-object-cannot-be-bound-to-any-parameters/15620/1 "2021-02-11T04:29:46Z")

</div>

Good day,

Noob here:

I am trying to get a list of open ports and then using the PID to lookup processname and username, all packed in to an array:

```auto
[array]$ports = get-nettcpconnection | Select-object state, creationtime, localaddress, localport, owningprocess, remoteport, remoteaddress
foreach($i in $ports.owningprocess)
{
Get-Process -Id $i -IncludeUserName | 
Add-Member -inputobject $ports -NotePropertyMembers @{
processname = $_.processname
username = $_.username}

}

```

but i just get the following error:

“Add-Member : 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.  
At line:5 char:1”

What am I doing wrong here? Or is there an entirely different and better way of doing this?

&nbsp;

Thank you in advance

Regards

---

<div class="post-metadata">

**Author:** ![andysvints](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/andysvints/32/1017_2.png) [@andysvints](https://forums.powershell.org/u/andysvints)\
**Post date:** [March 5, 2021, 7:29pm UTC](https://forums.powershell.org/t/add-member-the-input-object-cannot-be-bound-to-any-parameters/15620/2 "2021-03-05T19:29:20Z")

</div>

Hello @hanskapans,  
Couple of comments:

1. On the first line you are selecting only 3 properties ( **State, CreationTime, LocalAddress** ) and then in the `foreach` loop you are using **OwningProcess**
2. When you are trying to Add-Member, the Add-Member cmdlet should be the first one in the pipeline.

I would suggest the following:

```auto
#Create Collection of PSCustom Objects with only needed properties from get-nettcpconnection
#Loop through all ports and use Add-Member to add User and Process name

```

Quick & dirty way:

```auto
$PortsList=New-Object System.Collections.Generic.List[PSObject]

$ports = get-nettcpconnection 
foreach($i in $ports)
{

    $ProcessInfo=Get-Process -Id $i.owningprocess -IncludeUserName
    Add-Member -inputobject $ports -NotePropertyMembers @{
    processname = $_.processname
    username = $_.username}

    $prop=[ordered]@{
        state=$i.state
        creationtime=$i.creationtime
        localaddres=$i.localaddres
        processname=$ProcessInfo.processname
        username=$ProcessInfo.username
    }
    $obj=New-Object -TypeName psobject -Property $prop
    $PortsList.Add($Obj)

}

```

Output:

 ![portslist](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/3/3348608d35d92447aa62188f754e896a4ac3a1f3.png)

Hope that helps.

---

<div class="post-metadata">

**Author:** ![tluizzi](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tluizzi/32/1033_2.png) [@tluizzi](https://forums.powershell.org/u/tluizzi)\
**Post date:** [March 8, 2021, 11:45pm UTC](https://forums.powershell.org/t/add-member-the-input-object-cannot-be-bound-to-any-parameters/15620/3 "2021-03-08T23:45:31Z")

</div>

I removed the Add-Member cmdlet within the foreach loop

```auto
$ports = Get-NetTCPConnection
$PortsList = foreach($i in $ports)
{
    $ProcessInfo= Get-Process -Id $i.owningprocess -IncludeUserName

    $prop=[ordered]@{
        State = $i.State
        CreationTime = $i.CreationTime
        LocalAddress = $i.LocalAddress
        ProcessName = $ProcessInfo.ProcessName
        Username = $ProcessInfo.Username
    }
    New-Object -TypeName pscustomobject -Property $prop
}

$PortsList | Format-Table -AutoSize

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:27pm UTC](https://forums.powershell.org/t/add-member-the-input-object-cannot-be-bound-to-any-parameters/15620/4 "2024-05-16T20:27:46Z")

</div>

Closed on May 16, 2024, 8:27pm UTC


