[英]how to get expiration date for users in a CSV file using PowerShell?
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
This works great but gets all USERS in AD. 这很好用,但使所有用户都进入了广告。 We have thousands of Users.
我们有成千上万的用户。
I want to get users that are in a CSV file (1st column). 我想获取CSV文件(第一列)中的用户。 If possible, I'd love to create a second column in the same file with the expiration date.
如果可能的话,我想在同一文件中用到期日期创建第二列。
The CSV file CSV文件
Jason.Bourne
Thomas.Smith
Judy.Doe
Topsy.kret
I modified my PowerShell Script but not sure how to get the value from the CSV file into Get-ADUser 我修改了PowerShell脚本,但是不确定如何将CSV文件中的值转换为Get-ADUser
With a samaccountname
header in the csv file: 在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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.