Really simple..
Looking to create a powershell script that returns an AD result if a user is found.
I'm using FirstName and Surname as variables. My script so far looks a little something like this...
$FirstName = Read-Host "Please enter the First Name of the new user"
$Surname = Read-Host "Please enter the Surname of the new user"
Get-ADUser -f "GivenName -eq '$FirstName'" -and "Surname -eq '$Surname'"When I run each part of the Get-ADUser command (so search by first name, search by surname) it returns the expected result.
When I add -and as an operator, so both conditions are satisfied, I get this:
Get-ADUser : A parameter cannot be found that matches parameter name 'and'.
At line:4 char:44
+ Get-ADUser -f "GivenName -eq '$FirstName'" -and "Surname -eq '$Surnam ...
+ ~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ADUser], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management. Commands.GetADUserWhere in the hell am I going wrong!?
11 Answer
I tried this and worked,
$FirstName = Read-host 'enter first name'
$LastName = Read-Host 'enter last name'
Get-ADUser -Filter "GivenName -eq '$FirstName' -and SurName -eq
'$LastName'"check for the quotes on your code