I'm writing a script to identify all interns in the copmany. They all have the word intern in the description field of their AD account. However it could say intern, engineering intern, intern for telecom, or any other combo.
Using the below code I can catch all of those other permutations. the problem is it is also picking up employees who have descriptions like international, internet, internal.
I'm having trouble figuring out how to write the variable for the description in a way that will catch everything all those with intern somewhere in the field, but exclude if intern is part of a larger word. Allof my attempts have failed. they either filter out everything or nothing.
I know I could do something like -filter {(description -like $value1) -and (description -notlike "*international*")}, but I need it to be flexible enough to catch anything similar to that without having to hard code all of those exceptions.
Import-Module ActiveDirectory $searchbase = "ou=xxx,dc=xxx,dc=xxx,dc=xxx" $value1 = "*intern*" Get-ADUser -searchbase $searchbase -filter { (description -like $value1) } -properties * |select-object name, description , lastlogondate,enabled |sort-object lastlogondate