PowerShell - 获取 AD 中所有非残疾用户的密码到期时间 [英] PowerShell - Get Password Expiration for all non Disabled Users in AD

查看:73
本文介绍了PowerShell - 获取 AD 中所有非残疾用户的密码到期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在 powershell 中创建一个对象,显示所有非禁用用户的 AD 显示名称和密码到期日期.这相对容易.但是,日期是以不可读的格式检索的,所以我转换了日期.

My goal is to create a single object in powershell that shows the AD display name and password expiration date for all non-disabled users. This is relatively easy. However, the date is retrieved in an unreadable format so I convert the date.

正在创建包含我想要的数据的两个变量.问题是当我尝试组合这两个变量时,我得到了一个带有两个标题的单个对象,但下面的两列是空的.

Creating the two variables that contain the data I want is working. The problem is when I try to combine those two variables I get a single object with two headers as expected but the two columns below are empty.

我在 Win 7 Pro SP1 上使用 PowerShell V2

I'm using PowerShell V2 on Win 7 Pro SP1

任何想法可能是什么问题?

Any ideas what the issue could be?

# Get users DisplayName and password expiration time from AD
$msdsComputed = Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq  $False} -Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" |  
        Where-Object {$_.DisplayName -ne $null} 

# Convert date to human readable format
$ExpiryDate = $msdsComputed | Foreach-Object {
             ([datetime]::FromFileTime(($_)."msDS-UserPasswordExpiryTimeComputed")) 
                          } | Select-Object "DateTime"



$combined = @{            
              DisplayName   = $msdsComputed.DisplayName
              ExpiryDate    = $ExpiryDate.DateTime
             }
New-Object PSObject -Property $combined | ConvertTo-Csv -NoTypeInformation

推荐答案

这是您的脚本的修订版,没有循环问题:

Here's a revised version of your script without looping issues:

$reportObject = @()
$userList = Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq  $False} -Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" |  Where-Object {$_.DisplayName -ne $null}
$userList | %{

    $output = "" | Select DisplayName, ExpiryDate
    $output.DisplayName = $_.DisplayName
    $output.ExpiryDate = ([datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")).DateTime
    $reportObject += $output
    #Next 2 Lines provide debugging... I'm not sure the date time portion will work without having AD to play with
    $output | fl *
    ([datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")).DateTime 
}

$reportObject | Convertto-CSV -NoTypeInformation

这篇关于PowerShell - 获取 AD 中所有非残疾用户的密码到期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆