none
remove duplicate entries from object RRS feed

  • Question

  • hi

    i have a script which query event viewer for login information and store them in object. but i want to remove duplicate entries because alot of them are duplicate. like this:

    Username                     Time                  LogonType Location                          
    --------                     ----                  --------- --------                          
    HQ\K.Damon                   6/18/2018 10:16:34 AM         3 172.16.0.188             
    HQ\K.Damon                   6/18/2018 10:16:34 AM         3 172.16.0.188              
    HQ\K.Damon                   6/18/2018 10:16:32 AM         3 172.16.0.188            
    HQ\H.Katy                    6/18/2018 10:16:25 AM         3 -                        
    HQ\H.Katy                    6/18/2018 10:16:25 AM         3 172.22.165.160          
    HQ\S.Sutra                   6/18/2018 10:16:24 AM         3 172.18.2.181       
    HQ\S.Sutra                   6/18/2018 10:16:24 AM         3 172.18.2.181      
    HQ\S.Sutra                   6/18/2018 10:16:23 AM         3 172.18.2.181      
    

    i want remove entries if (username AND time AND location AND logontype) were the same and return only one of them.

    tried select-object -unique and get-unique but they return only based on one property. looking for a way to get unique based on 4 properties.

    thanks

    Monday, June 18, 2018 6:10 AM

All replies

  • Use "Select-Object -Unique".

    help Select-Object -online


    \_(ツ)_/

    Monday, June 18, 2018 6:27 AM
  • i tried that before. it return only first row. this is strange, because even i use select-object -property username,time,location -unique but it returns first row. 
    Wednesday, June 20, 2018 3:20 AM
  • You can try this to see if it can manage the objects:

    sort-object username,time,location  -Unique


    \_(ツ)_/

    Wednesday, June 20, 2018 3:48 AM
  • unfortunatly no ! :(

    it returns all object with your sort-object even when i include properties.

    there is no distinct like feature in powershell like sql? so i can easily get unique values using a combination of properties? 

    Wednesday, June 20, 2018 4:07 AM