简体   繁体   English

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

[英]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.

相关问题 获取证书到期日期 powershell - get certificate expiration date powershell 使用Ubuntu机器上的Powershell获取SSL证书的到期日期 - Get SSL certificates expiration date using powershell on ubuntu machine 我们如何使用PowerShell脚本转换CSV文件中的日期 - How can we transform Date in CSV file using PowerShell scripts Powershell 脚本,通过 output 到 csv 找到密码到期的特定日期 - Powershell script that finds password expiration by a specific date with output to csv 使用 foreach 从 csv 文件获取多个用户的 Powershell - Powershell for get-aduser for multiple users from a csv file with foreach PowerShell - 获取AD中所有非禁用用户的密码到期时间 - PowerShell - Get Password Expiration for all non Disabled Users in AD 使用PowerShell从CSV文件更新AD用户 - Using PowerShell to update AD users from CSV file 如何使用PowerShell将用户从CSV文件添加到Active Directory(AD)和Exchange中? - How do you add users from a CSV file to Active Directory (AD) and Exchange using PowerShell? 如何使用Powershell CSV或文本文件将多个USERS访问权限导入多个邮箱 - How to import multiple USERS access-rights to multiple Mailboxes using Powershell CSV or Text File 如何使用 PowerShell 获取特定日期范围的文件计数 - How to get a specific date range file count using PowerShell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM