Skip to content

Instantly share code, notes, and snippets.

@NonSecwitter
Created March 6, 2017 13:16
Show Gist options
  • Save NonSecwitter/df79769433d2fab8055518b1ba409fa9 to your computer and use it in GitHub Desktop.
Save NonSecwitter/df79769433d2fab8055518b1ba409fa9 to your computer and use it in GitHub Desktop.
Function Append-LevDistance
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true, Position=2)]
[Object]
[ref]$Users,
[Parameter(Mandatory=$true, Position=0)]
[String]
$FirstName,
[Parameter(Mandatory=$true, Position=1)]
[Object]
$LastName
)
Function Set-Distance ([int]$distance1, [int]$distance2)
{
if ($distance1 -gt ($SearchName.Length/2)-AND $distance2 -gt ($SearchName.Length/2))
{
$Users.Remove($User)
}
elseif($distance1 -le $distance2)
{
$Users[$Users.IndexOf($User)].LevDistance = $distance1
}
else
{
$Users[$Users.IndexOf($User)].LevDistance = $distance2
}
}
$SearchName = $FirstName + $LastName
if (($FirstName -eq "") -OR ($LastName -eq ""))
{
foreach ($User in $Users.ToArray())
{
$distance1 = Get-LevDistance $SearchName $User.GivenName
$distance2 = Get-LevDistance $SearchName $User.SurName
Set-Distance $distance1 $distance2
}
}
else
{
foreach ($User in $Users.ToArray())
{
$ADName1 = $Users[$i].GivenName + $Users[$i].Surname
$ADName2 = $Users[$i].SurName + $Users[$i].Givenname
$distance1 = Get-LevDistance $ADName1 $SearchName
$distance2 = Get-LevDistance $ADName2 $SearchName
Set-Distance $distance1 $distance2
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment