$cred = Get-Credential “[email protected]”
Connect-MsolService -Credential $cred
$domain = Get-MsolDomain | where {$_.IsDefault -eq $true}
$PasswordPolicy = Get-MsolPasswordPolicy -DomainName $domain.Name
$Account = “[email protected]” # Change HERE !!
$UserPrincipal = Get-MsolUser -UserPrincipalName $Account
$UserPrincipal | fl PasswordNeverExpires
$PasswordExpirationDate = $UserPrincipal.LastPasswordChangeTimestamp.AddDays($PasswordPolicy.ValidityPeriod)
Write-host “Password will Expire on : $PasswordExpirationDate”
$StartDate = (GET-DATE)
$DaysLeft = NEW-TIMESPAN -Start $StartDate -End $PasswordExpirationDate
$DaysLeft = [math]::Floor($DaysLeft.TotalDays)
Write-host “Password will Expire in # Days : $DaysLeft”
$UserPrincipal | select DisplayName, LastPasswordChangeTimeStamp,@{Name=”PasswordAge”;Expression={((Get-Date).ToUniversalTime())-$_.LastPasswordChangeTimeStamp}} | sort-object PasswordAge -desc
Leave a Reply
You must be logged in to post a comment.