0

Looking for a little explanation as to why this isn't working and what I might be doing wrong. Any Help would be great!

Expected Results : BSMITH

Get-Aduser -filter {(givenname -eq "Bob") -and (surname -eq "Smith"))} | select-object SamAccountName

Result : BSMITH

Works Fine. Good to go


Expected Result : BSMITH

$textbox_FirstName = "Bob"
$textbox_LastName = "Smith"

Get-Aduser -filter {(givenname -eq "$textbox_FirstName.text") -and (surname -eq "$textbox_LastName.text")} | select-object SamAccountName

Result : (Blank Nothing)

I have tried givenname -eq "$textbox_FirstName.text" without quotes, without .text, with no quotes at all. Still no results :(

1 Answer 1

1

Both variables are of the type string they don't have a .text property, in addition adding double quotes to your variable would expand the variable and concatenate .text:

$textbox_FirstName = "Bob"
"$textbox_FirstName.Text" => Bob.Text

Any of these options should give you the output you expect:

Get-Aduser -Filter {GivenName -eq $textbox_FirstName -and Surname -eq $textbox_LastName}
Get-Aduser -Filter "GivenName -eq '$textbox_FirstName' -and Surname -eq '$textbox_LastName'"
Get-Aduser -LDAPFilter "(&(GivenName=$textbox_FirstName)(Surname=$textbox_LastName))"
Sign up to request clarification or add additional context in comments.

2 Comments

Ultimately this is what my final code looked like. Which is a little more outside the scope of the original question. But your answer certainly got me on the correct path. Thank you very much for your help!! $textbox_psOutput.Text = Get-Aduser -Filter {(Surname -eq $Textbox_Lastname.Text -and GivenName -eq $Textbox_FirstName.Text)} | Select-Object SamAccountName | Out-String
Happy to help @KyleMason

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.