如何使用powershell脚本过滤用户

How to filter users with powershell script

我想获取具有特定电子邮件 ID 的 AD 用户的用户属性(如 SAMNAME、First Name、Last NAme 等),然后将其输出到 csv 文件,如何使用 power-shell 脚本?

Get-ADUser -searchbase $searchLoc -Properties *,"msDS-UserPasswordExpiryTimeComputed",PasswordNeverExpires -Filter * | Select-Object @{Label = "SAM Account Name";Expression = {$.SamAccountName}}, @{Label = "First Name";Expression = {$ .GivenName}}, @{Label = "Last Name";Expression = {$.Surname}}, @{Label = "Email Address";Expression = {$.mail }} | Convertto-Csv -NoTypeInformation -分隔符“,” | %{$_ -replace '"',""} | out-file $reportpath -fo -Encoding ascii

尝试这样的事情:

 Get-ADUser -Filter "*" | where UserPrincipalName -eq "test@domain.fr" | select name, surname, SamAccountName