【问题标题】:Sorting Get-ADUser output by password expiry date按密码到期日期对 Get-ADUser 输出进行排序
【发布时间】:2018-01-02 21:52:30
【问题描述】:

我正在运行一个 powershell 脚本来获取 AD 用户及其密码到期日期。我想根据他们的密码到期日期对输出进行排序。

这是脚本:

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")}
                                          } > result.txt

如何按ExpiryDate 字段对结果进行排序/显示?

【问题讨论】:

标签: powershell sorting active-directory


【解决方案1】:

Get-ADUser 输出上使用sort-object cmdlet,如下所示:

| Sort-Object -property ExpiryDate

所以整个事情看起来像这样:

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")}
                                             } | 
    Sort-Object -property ExpiryDate > result.txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 2014-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多