Book Image

Active Directory with PowerShell

By : Pamarthi Venkata Sitaram, YELLAPRAGADA U PADMAVATHI
5 (1)
Book Image

Active Directory with PowerShell

5 (1)
By: Pamarthi Venkata Sitaram, YELLAPRAGADA U PADMAVATHI

Overview of this book

Table of Contents (16 chapters)
Active Directory with PowerShell
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting the password expiry date of user accounts


The function discussed in this section helps in retrieving the password expiry date of the users in the domain. The good thing with this function is that it makes use of the msDS-UserPasswordExpiryTimeComputed attribute of the user accounts to determine the password expiry date. This attribute stores a dynamic value that indicates the date and time when the password of the user is going to expire. This value will be in the FileTime format. This function looks for user accounts that are enabled and has the PasswordNeverExpires attribute set to false:

Function Get-PasswordExpiryDetails {
[CmdletBinding()]
Param(
)
$Users = Get-ADUser -Filter {PasswordNeverExpires -eq $false -and  Enabled -eq $true} `-Properties msDS- UserPasswordExpiryTimeComputed,*

Foreach($User in $Users) {
  $OutputObj = New-Object -TypeName PSObject -Property @{
          UserName = $User.Name;
          DisplayName = $null;
          PwdExpirtyDate = $null;
          PwdExpiryInDays...