I have a variable I pull from a form that I need to tie in with a matching display name to retrieve an existing samAccountName.
If (Get-ADUser -Filter { (displayName -eq $user) -AND ($Returner -eq "Yes")} ) {
$Check = Get-ADUser -Filter{displayName -eq $user} -Properties SamAccountName
$sam = $check.SamAccountName
$sam
}
As soon as I have the -AND ($Returner.....) part in there the check fails to execute.
I need that check in there as that is what is passed from the Cherwell form to flag that a user is a returner and then I am going to pull in the current samAccountName for that person.
Can someone assist on how I should be using a check of a parameter in with the Get-ADUser command.
Many thanks
S.
scriptblockformat for your-Filter... but that parameter requires a string. the "brilliant persons" who designed the AD module allow the scriptblock format [and use it for many examples], but it is not reliable for complex filters. you likely will need to switch to a string similar to >>>-Filter "(displayName -eq $user) -AND ($Returner -eq 'Yes')"<<<