简体   繁体   中英

get-aduser from csv file lastlogon passwordexpire

The below script gives me the proper input for one account, when multiple accounts are added it does not work. How can I get it to work for all user accounts listed in the csv file?

$csv = import-csv "c:\users.csv"

foreach($user in $csv){
$Displayname = $user.Displayname
Get-aduser -filter {displayname -eq $displayname}`
-Properties displayName,employeeID,mail, "msDS-UserPasswordExpiryTimeComputed","lastLogonTimestamp" |`
 select "Displayname","Enabled",@{Name="PasswordExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}},@{N='LastLogonTime'; E={[DateTime]::FromFileTime($_.lastLogonTimestamp)}},SamAccountName,employeeID,mail |`
Export-Csv "c:\temp\users1.csv"
}

您需要将-append开关添加到export-csv否则,该文件将在每次循环时被覆盖,仅保留列表中最后一个用户的详细信息

Export-Csv "c:\temp\users1.csv" -append

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM