Sorry--Noticed typo $Right = "Azarael" $Wrong = "Az*rael" $Right -like $Wrong. True
Jim Jim Robertson Systems Administrator Ext. 7808 -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Jim Robertson Sent: Tuesday, August 4, 2015 10:21 AM To: '[email protected]' Subject: RE: [powershell] Confused about -Like comparison 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 A regex is often used to do the pattern match. 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
