Hello, I’m a PS beginner! I’m trying to create a report and I want to filter out the results so I only get back certain companies (i.e. Company like “Paul”). When I try adding a -Filter to the Get-AdUser statement, it errors out with
Get-ADUser : Parameter set cannot be resolved using the specified named parameters.
At C:\Work\test.ps1:10 char:34
+ … tNames | % {Get-ADUser -Filter {Company -like “Paul”} -Identity $_.s …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: ( [Get-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.ActiveDirectory.Management.Commands.GetADUser
$Details = $sAMAccountNames | % {Get-ADUser -Filter {Company -like “Paul”} -Identity $_.sAMAccountName -Properties DisplayName, LastlogonDate, Enabled, AccountLockoutTime, LastBadPasswordAttempt, BadPwdCount, LockedOut, Company, Description}
Here is my working code, but without the filter.
$LockedRpt = “c:\work\LockedAccounts.csv”
delete the existing output file
$exists = Test-Path $LockedRpt
If ($exists -like “True”)
{
Remove-Item $LockedRpt
}
Import-module ActiveDirectory -ErrorAction stop
$sAMAccountNames = Search-ADAccount -UsersOnly -LockedOut | Select SamAccountName
$Details = $sAMAccountNames | % {Get-ADUser -Identity $_.sAMAccountName -Properties DisplayName, LastlogonDate, Enabled, AccountLockoutTime, LastBadPasswordAttempt, BadPwdCount, LockedOut, Company, Description}
$Details | Select SamAccountName, DisplayName, LastlogonDate, Enabled, AccountLockoutTime, LastBadPasswordAttempt, BadPwdCount, LockedOut, Company, Description | Export-Csv c:\work\LockedAccounts.csv -NoTypeInformation
Thanks for any help!