I need some help to eliminate duplicate entries in a hashtable.
Code:
$username=Get-Content ".\u.txt"
#$username
$fileread=Get-Content ".\lastlogon.txt"
$lastinfo=$fileread|select-string -pattern "logged off" -encoding ASCII
foreach($i in $lastinfo){
$splitinfo=$i -split("Login ID: ")
$dateinfo=$splitinfo[0] -split(" ")
$finaldateinfo=$dateinfo[2] -split(" ")
#$finaldateinfo[0]
$userinfo=$splitinfo[1] -split(" ")
#$userinfo[0]
$hashinfo= @{$userinfo[0]=$finaldateinfo[0]}
#$hashinfo
foreach($h in $hashinfo.GetEnumerator()){
foreach($a in $username){
if($hashinfo.ContainsKey($a)){
"$($hashinfo.keys):$($hashinfo.Values)"
}
}
}
}
Result:
Name Value
---- -----
USERID 08/03/2018
USERID 09/03/2018
USERID 10/03/2018
USERID 13/03/2018
ADM 23/03/2018
The hashtable is like this.
I need only the last entry of USERID to be kept and eliminate all the other values of USERID.