Link to home
Start Free TrialLog in
Avatar of Loyall
LoyallFlag for Netherlands

asked on

Powershell find users with similar family names

Hi,

I have a script that searches for users that have the exact Firstname I provide and Surnames that are alomst identical
So, when I provide the script the firstname "Sara" and surname "Smith", I want it to find al users that have names like:

Sara Smith
Sara Smithonian
Sara Smith Klein etc.

I'm using this line:
$names = $(try {Get-Aduser -filter * -Properties Surname | Where {$_.Givenname -like "$Givenname" -and $_.Surname -like "*$Lastname*"}} catch {$null})

I kind of works. It just finds only users that have the exact First and Surname I provide the script.
So, in the example above, it only finds all the "Sara Smiths" in AD, but not the Sara's with similar familynames.

How can I get this done ?
Thanks in advance.
SOLUTION
Avatar of Guy Lidbetter
Guy Lidbetter
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Loyall

ASKER

I'm very sorry for my delayed response. I will test it tomorrow.
Avatar of Loyall

ASKER

My question has been answered