# Please help me with filtering data.

**URL:** <https://forums.powershell.org/t/please-help-me-with-filtering-data/10735>\
**Category:** PowerShell Help\
**Created:** [June 1, 2018, 4:32am UTC](https://forums.powershell.org/t/please-help-me-with-filtering-data/10735 "2018-06-01T04:32:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![poratfreak](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@poratfreak](https://forums.powershell.org/u/poratfreak)\
**Post date:** [June 1, 2018, 4:32am UTC](https://forums.powershell.org/t/please-help-me-with-filtering-data/10735/1 "2018-06-01T04:32:44Z")

</div>

Hi,

I need to remove rows that have duplicates PC\_NAME, but I cannot seem to get it working.  
I can only make it work if I select one object but I need to returns the entire rows.  
I do not care what DATA is in the row, I only need to make sure that the PC\_NAME is unique.

Let’s say I have this data:

PC\_NAME DATA

* * *

PC\_1 AJRouter  
PC\_1 AppIDSvc  
PC\_2 Server  
PC\_3 Oracle  
PC\_3 Oracle-temp

I want to return this:  
PC\_NAME DATA

* * *

PC\_1 AJRouter  
PC\_2 Server  
PC\_3 Oracle

This script is only returning the PC\_NAME and not the entire rows:

$my\_filtered\_data = $pc\_list | Select-Object -Property PC\_NAME -Unique  
$my\_filtered\_data

---

<div class="post-metadata">

**Author:** ![random-commandline](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@random-commandline](https://forums.powershell.org/u/random-commandline)\
**Post date:** [June 1, 2018, 5:28am UTC](https://forums.powershell.org/t/please-help-me-with-filtering-data/10735/2 "2018-06-01T05:28:14Z")

</div>

I am sure there are other ways of doing this, but using Group-Object can work.

```
$content = 'PC_NAME DATA
PC_1 AJRouter
PC_1 AppIDSvc
PC_2 Server
PC_3 Oracle
PC_3 Oracle-temp'

# Convert string to custom object then group objects
$group = $content | ConvertFrom-Csv -Delimiter ' ' | 
Group-Object -Property PC_Name 

# Select first object in each group
$group | ForEach-Object {$_.Group | Select-Object -First 1}
```

---

<div class="post-metadata">

**Author:** ![poratfreak](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@poratfreak](https://forums.powershell.org/u/poratfreak)\
**Post date:** [June 1, 2018, 5:49am UTC](https://forums.powershell.org/t/please-help-me-with-filtering-data/10735/3 "2018-06-01T05:49:48Z")

</div>

Thanks a lot! It’s working great.

---

<div class="post-metadata">

**Author:** ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)\
**Post date:** [June 1, 2018, 6:37am UTC](https://forums.powershell.org/t/please-help-me-with-filtering-data/10735/4 "2018-06-01T06:37:15Z")

</div>

```
import-csv unique.csv | sort -u pc_name                                                                                          

PC_NAME DATA
------- ----
PC_1 AJRouter
PC_2 Server
PC_3 Oracle
```

---

<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:35pm UTC](https://forums.powershell.org/t/please-help-me-with-filtering-data/10735/5 "2024-05-16T20:35:52Z")

</div>

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


