在 PowerShell 中获取 Azure Active Directory 密码到期日期 [英] Get Azure Active Directory password expiry date in PowerShell
问题描述
我正在使用 Azure Active Directory,想知道用户的密码何时到期.
I am working with Azure Active Directory and want to know when a user's password expires.
目前我使用这些 PowerShell 命令成功连接到 msol 服务并获取密码到期日,但我不太确定如何获取密码到期日.
Currently I use these PowerShell commands to connect to msol service successfully and get password expiry, but I'm not quite sure how to get password expiry date.
我正在使用 Azure Active Directory PowerShell 模块.
I am using Azure Active Directory PowerShell module.
Connect-MsolService
Get-MsolUser -UserPrincipalName 'Username' | Select PasswordNeverExpires
推荐答案
您正在寻找 LastPasswordChangeTimestamp
属性:
Get-MsolUser -UserPrincipalName 'Username' |Select LastPasswordChangeTimestamp
这只会告诉您密码上次更改的时间,而不是密码到期的时间,因此还要从密码策略中获取密码有效性:
This only tells you when the password was last changed, not when it will expire, so grab the password validity from the Password Policy as well:
$PasswordPolicy = Get-MsolPasswordPolicy
$UserPrincipal = Get-MsolUser -UserPrincipalName 'Username'
$PasswordExpirationDate = $UserPrincipal.LastPasswordChangeTimestamp.AddDays($PasswordPolicy.ValidityPeriod)
$PasswordExpirationDate
现在应该有密码过期的时间戳
$PasswordExpirationDate
should now have the timestamp for when the password expires
这篇关于在 PowerShell 中获取 Azure Active Directory 密码到期日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!