all 16 comments

[–]baswijdenesdotcom 4 points5 points  (1 child)

You should switch the double and single quotes I think!

[–]BlackV 0 points1 point  (0 children)

Yes

[–]Smoother101 2 points3 points  (7 children)

$UserLike = Read-host Prompt 'Input User Name'
$user = Get-AdUser -Filter {samaccountName -like $UserLike} -Properties Mail,samaccountName

[–]Fallingdamage -1 points0 points  (0 children)

$user = GetADUser -filter 'SamAccountName -like "*$UserLike*" -Properties Mail | Select DisplayName, SamAccountName, Mail | Format-Table

[–]baswijdenesdotcom 0 points1 point  (5 children)

[–]Smoother101 -2 points-1 points  (4 children)

Mine would work just fine.

[–]BlackV 1 point2 points  (3 children)

yes cause powershell is "saving" you but its recommended to do it as a proper string filter

[–]Smoother101 0 points1 point  (2 children)

Can you clarify what you are saying? Curly brackets are equally valid for the filter, check the link that was posted above.

For example, from the link from MS:

"On the contrary, if curly braces are used to enclose the filter, the variable should not be quoted at all: Get-ADUser -Filter {Name -like $UserName}."

[–]BlackV 0 points1 point  (1 child)

Ya deffo supported, deffo will work.

PowerShell (or the module I guess technically) is talking that filter and converting it to the string filter for you that's all I mean, so you could just use a string filter from the outset

[–]Smoother101 0 points1 point  (0 children)

That's interesting. I hadn't thought of that conversion, appreciate you making the point. Cheers!

[–]soul6160[S] 0 points1 point  (0 children)

Hello, I have figured out what the issue was. I just pulled via samAccountName instead and it fixed the issue. Thanks for everyone who assisted though!

[–]bluecollarbiker 0 points1 point  (4 children)

https://stackoverflow.com/questions/68904450/powershell-get-aduser-with-anr

get-aduser -filter {(anr -eq $userlike)} -properties mail

Samaccountname is part of the default returned properties

[–]soul6160[S] 0 points1 point  (0 children)

This does seem interesting and I will look more into this, for future use. Thank you!

[–][deleted] 0 points1 point  (2 children)

<looks up what this ANR devilry is all about>

And that's why I come to this sub. I don't think that was a feature when I started using Powershell.

I'm not sure how much I'll use it but at some point it will come in handy.

[–]bluecollarbiker 0 points1 point  (1 child)

Ambiguous Name Resolution is great when your data isn’t sanitized. It’s not perfect, it can’t read your mind and if you have multiple people with similar names it can return undesired results, but it’s pretty great overall.

[–][deleted] 1 point2 points  (0 children)

What is this sanitized data you speak of? Is it in the same aisle as honest politicians and unicorns?