如何使用powershell脚本过滤用户

时间:2017-01-23 12:57:12

标签: powershell windows2012

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

Get-ADUser -searchbase $ searchLoc -Properties *,&#34; msDS-UserPasswordExpiryTimeComputed&#34;,PasswordNeverExpires -Filter * | Select-Object @ {Label =&#34; SAM Account Name&#34 ;; Expression = {$ .SamAccountName}},@ {Label =&#34; First Name&#34 ;; Expression = {$ .GivenName}},@ {Label =&#34; Last Name&#34 ;; Expression = {$ .Surname}},@ {Label =&#34; Email Address&#34 ;; Expression = { $ .mail}} | Convertto-Csv -NoTypeInformation -delimiter&#34;,&#34; | %{$ _ -replace&#39;&#34;&#39;,&#34;&#34;} | out-file $ reportpath -fo -Encoding ascii

1 个答案:

答案 0 :(得分:2)

尝试这样的事情:

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