MO-Senpai
MO-Senpai

Reputation: 57

PowerShell script to find the user password expiry date and renew it to a custom date

I want to find a PowerShell script to find the user password expiry date and time and renew it to customized time for bulk users.

I tried it with with the below code:

Get-MsolUser -UserPrincipalName '[email protected]' | select *password* |fl 

This can fetch only last password change but not when the password will expire.

Upvotes: 0

Views: 3828

Answers (1)

DSSO21
DSSO21

Reputation: 129

There is no field you can query for this task. You have to do this in two steps.

  1. Get the password policy

    $PasswordPolicy = Get-MsolPasswordPolicy
    
  2. Calculate the time to the next password expiry date with some math magic

    $(Get-MsolUser -UserPrincipalName  "SuperUser").LastPasswordChangeTimestamp.AddDays($PasswordPolicy.ValidityPeriod)
    

More details can be found here Office 365 – Retrieve User Password Expiration Date

Upvotes: 1

Related Questions