Where-Object : A parameter cannot be found that matches parameter name 'SearchBase'

Hi Heroes,

When I am running the below script portion I am encountering error “Where-Object : A parameter cannot be found that matches parameter name ‘SearchBase’.” I am sure that the searchbase path given is correct. Any help would be much appreciated. Thanks in advance.

$users = get-aduser -filter * -properties Name, PasswordNeverExpires, PasswordExpired, PasswordLastSet, EmailAddress |where {$.Enabled -eq “True”} | where { $.PasswordNeverExpires -eq $false } | where { $_.passwordexpired -eq $false } -SearchBase “OU=childOU,OU=parentOU,DC=domainname,DC=com”
$maxPasswordAge = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge

Syam,

the error message does not complain about the value you provided for the paramter -SearchBase! :wink: You provided the parameter for the cmdlet Where-Object not Get-ADUser. The proper command line should look something like this:

$users = 
Get-ADUser -Filter * -SearchBase 'OU=childOU,OU=parentOU,DC=domainname,DC=com' -Properties Name, PasswordNeverExpires, PasswordExpired, PasswordLastSet, EmailAddress | 
Where-Object { $_.Enabled -and -not $_.PasswordNeverExpires -and -not $_.passwordexpired }

If you take a look at your post you may notice that your code is actually broken. That happens when you do not format it as code. To do so, please, next time you post code place your cursor in an empty line click on the preformatted text button ( </> ) and paste your code.

Thanks in advance.

Wow Olaf,

It worked in my test set up. I will try that now in my prod for a different set of users and will update thread. You are awesome !! Thanks a lot :slightly_smiling_face:

Regards,
Syam.

Thanks so much Olaf,

It worked nicely :slight_smile: Thanks a lot.

Regards,
Syam.