I suggest you use Get-AdUser and the LDAPFilter parameter or the Filter parameter with a regex.
-----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Michael Leone Sent: Tuesday, August 4, 2015 11:26 AM To: [email protected] Subject: Re: [powershell] Confused about -Like comparison On Tue, Aug 4, 2015 at 11:20 AM, Jim Robertson <[email protected]> wrote: > Like is normally used for a partial string match and needs wildcards to > create an expression that does the match: > $Right = "Azarael" > $Wrong = "Az*rel" > $Right -like $Wrong. > True > OK. But I'm not sure how that helps me. What I have is a file of names, and I am supposed to match them in AD. I can't just arbitrarily put a wildcard in the middle of a name, and then try to find that wildcarded name in AD. > A regex is often used to do the pattern match. If I was any good at regexs, I would use one. :-) > > Hope that ehlps > > Jim > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Michael Leone > Sent: Tuesday, August 4, 2015 10:11 AM > To: [email protected] > Subject: [powershell] Confused about -Like comparison > > OK, I will admit to being dense today. I have a user in AD, and we have > apparently spelled his first name wrong. Easily fixed manually. > But I decided to use this as a test case, to see if I could find him using a > Powershell search. And I kept failing. Then I noticed this: > >> $Right = "Azarael" >> $Wrong = "Azrael" >> $Right -like $wrong > False > > No wonder my filtering was failing, I was trying for "givenName -like > $Right", figuring I would catch him, and then replace the incorrect spelling. > > Get-QADuser -SizeLimit 0 -Enabled | Where-Object {($_.givenName -like > "Azarael")} > > > But why is it wrong? From looking at it, shouldn't the comparison be "True"? > There's only a 1 letter difference between the 2, isn't that enough to > qualify as "-like"? > > What comparison should I be using, so that looking for "Azarael" finds > "Azrael"? > > > ================================================ > Did you know you can also post and find answers on PowerShell in the forums? > http://www.myitforum.com/forums/default.asp?catApp=1 > > > ================================================ > Did you know you can also post and find answers on PowerShell in the forums? > http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1
