Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Cleaning up a list with duplicate user names.

$
0
0

I have exported a list of last logged on users form Citrix and I need to clean up the list so that each use only shows up in the list once.  Because the users have logged on to different desktops over time, they may have multle entries.  I do need to keep the name of one of the desktops they have logged into because this gives me the name of the Desktop Group they are using. 

Here is an exaple of the text file that I am cleaning up:

KQR\tdarxxx,KQR\ta-secrets-15
KQR\tdarxxx,KQR\ta-secrets-16
KQR\tdarxxx,KQR\ta-secrets-17
KQR\tdarxxx,KQR\ta-secrets-18
KQR\apaxxxa,KQR\ta-vision-01
KQR\dmxxxer,KQR\ta-vision-02
KQR\pzbxxxk,KQR\ta-vision-03
KQR\dmuxxxr,KQR\ta-vision-04
KQR\dmuxxxr,KQR\ta-vision-05
KQR\sprxxxa,KQR\ta-vision-06
KQR\hsexxxa,KQR\ta-vision-07
KQR\hsexxxa,KQR\ta-vision-08
KQR\mxxxan,KQR\ta-vision-10
KQR\mxxxan,KQR\ta-vision-11

once I have KQR\tdarxxx,KQR\ta-secrets-16 , I don't need any more info on him.

This doesn't work:

$chusers = Get-Content -Path C:\test\chusers.txt
$compare = @()
$flist=""
    foreach ($user in $chusers ){
            $temp = $user -match '^KQR\\(\w+)'
            $test = $Matches[1]
                  
                if($flist -notmatch $test){
                        $compare += $user
                   }#end if
  
              
    }#end foreach
    $compare 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles