PowerShell cmdlets help admins perform tasks that are beyond the scope of what can be achieved using the graphical user interface (GUI). However, using PowerShell can often be complex and time-consuming.
Consider checking for password age. Admins may want to find passwords that are nearing their expiry so they can send the respective users an email request to change their passwords. This can be achieved using PowerShell or with a tool such as ManageEngine ADSelfService Plus.
ADSelfService Plus, an identity security solution, provides several crucial reports and functions that enhance and often surpass what can be achieved via PowerShell.
Let's compare what it's like to get the password age using PowerShell vs. ADSelfService Plus.
Run this script in PowerShell to get the password age report:
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")}} Screenshot:
This command fetches the password age for all Active Directory users by calculating the difference between the current date and the password expiration date.
Get-ADUser -Filter * -Properties "msDS-UserPasswordExpiryTimeComputed" | Select-Object Name, @{Name="PasswordAge";Expression={(New-TimeSpan -Start $_."msDS-UserPasswordExpiryTimeComputed").Days}} To check when a particular user's password will expire, replace "username" with the actual username. This extracts the exact expiration timestamp for a given user.
$User = "username"
(Get-AdUser $User -Properties "msDS-UserPasswordExpiryTimeComputed")."msDS-UserPasswordExpiryTimeComputed" Active Directory stores the password expiry time in a non-human-readable format. Convert it to a readable date using the following command:
$expiry = (Get-AdUser -Identity "username" -Properties "msDS-UserPasswordExpiryTimeComputed")."msDS-UserPasswordExpiryTimeComputed" [datetime]::FromFileTime($expiry) Create a report of all users' password ages and export it to a CSV file for auditing. This creates a CSV report in C:\Reports\ with password age details.
Get-ADUser -Filter * -Properties "msDS-UserPasswordExpiryTimeComputed" | Select-Object Name, @{Name="PasswordAge";Expression={(New-TimeSpan -Start $_."msDS-UserPasswordExpiryTimeComputed").Days}} | Export-Csv -Path "C:\Reports\PasswordAgeReport.csv" -NoTypeInformation You can check the password age of a specific user using the following command:
Get-ADUser -Identity username -Properties "msDS-UserPasswordExpiryTimeComputed" | Select-Object Name, @{Name="PasswordExpiryDate"; Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}} Note: Replace username with the actual username to get their password expiration date.
Yes, run the following command to retrieve password for all users:
Get-ADUser -Filter * -Properties "msDS-UserPasswordExpiryTimeComputed" | Select-Object Name, SamAccountName, @{Name="PasswordExpiryDate"; Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}} If the msDS-UserPasswordExpiryTimeComputed property is empty, the user's password might be set to "never expire", or the domain might have no password expiration policy.