小编Not*_*uru的帖子

PowerShell - 获取AD中所有非禁用用户的密码到期时间

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

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

我在Win 7 Pro SP1上使用PowerShell V2

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

# 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
Run Code Online (Sandbox Code Playgroud)

passwords powershell

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

passwords ×1

powershell ×1