hey guys so im having issues with AD users,
this is the code that i have been using to search users in AD but i want to use -like cmd so that i dont have to fill in the User logon name (Pre-Windows 2000)
how do i do that?
Do you have any reason to create a PscustomObject? Get-Aduser already returns an object.
What is your end goal, searching for AD accounts where users name starts with x?
$Name = “Jeffrey”
$result = Get-ADuser -filter “Name -like ‘$name*’” -properties * -server something.local
I’d advise to only return the properties that you need
Get-ADuser -filter “Name -like ‘$name*’” -properties name,userprincipalname,employeeid and so on
i want to search for users in AD so if i have a name like: John.doe
i can just search john or doe and find him cause now i need to fill in (Pre logon name pre windows 2000) or else it wont find the user.
Hey @JariMeijer
Don’t know if your question is still open but you might use a search query like this one here, slightly similar to what PorreKaj suggested:
Get-ADUser -Filter { name -like "*john*" }
Get-ADUser -Filter { name -like "*doe*" }
In your code it will probably look like this:
Get-ADUser -Filter { name -like "*$UserTypedSearchString*" }
This will work either you type the firstname or lastname.
The trick is that you use two wildcard chars: one before and one after the typed search string. So it will return any objects that will match the search filter.
Hope this helps.
Best regards,
Don
yes it was still open! so i have not 1 Certain user i need to find but i need to be able to search for every user in AD( like how you are able to do in Active Directory itself, look at Screenshot) with there first or last name what kind of variable do i use for that?
Based on your example, you can definitely do it using my provided code.
Have you tried it?
Here is the code representation of what you’re achieving using dsa.msc
$UserTypedSearchString = "test"
Get-ADUser -Filter { name -like "*$UserTypedSearchString*" } # putting a * char before and anfter the variable ensures that it will catch up all results matching what the user has typed...
Give it a try… it will work 100%
yes it works, thank you!
Very good! I’m happy that it worked! Have fun with your project.
Best regards,
Don