首页 文章

如何使用PowerShell获取CSV文件中的用户的到期日期?

提问于
浏览
0
Import-CSV -Path .\csv_file.csv | ForEach-Object { 
    Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties “DisplayName”, “msDS-UserPasswordExpiryTimeComputed” |
    Select-Object -Property “Displayname”,@{Name=“ExpiryDate”;Expression={[datetime]::FromFileTime($_.“msDS-UserPasswordExpiryTimeComputed”)}}
} | Export-Csv .\results.csv -NoTypeInformation

这很有效,但在AD中获得所有用户 . 我们有数千名用户 .

我想获取CSV文件中的用户(第1列) . 如果可能的话,我很乐意在同一个文件中创建一个有效期限的第二列 .

CSV文件

Jason.Bourne
Thomas.Smith
Judy.Doe
Topsy.kret

我修改了PowerShell脚本,但不确定如何将CSV文件中的值传入Get-ADUser

1 回答

  • 2

    在csv文件中有 samaccountname 标头:

    Import-CSV -Path C:\folder\input.csv | ForEach-Object { 
        Get-ADUser -Identity $_.samaccountname –Properties DisplayName,msDS-UserPasswordExpiryTimeComputed,Enabled,PasswordNeverExpires | Select-Object -Property Displayname,Enabled,PasswordNeverExpires,@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}
    } | Export-CSV C:\folder\results.csv -NoTypeInformation
    

相关问题