Office 365:使用 PowerShell 获取上次密码更改日期
要求:检查 Office 365 中上次密码更改日期。
如何查看Office 365的最后一次密码更改?
安全的关键组成部分之一是管理密码。密码管理是维护数字领域安全的一个关键方面。对于 Microsoft 365 用户,了解密码何时过期对于避免帐户被锁定至关重要。在本综合指南中,我们将讨论检查 Office 365 中上次密码更改日期以及检查用户密码何时过期的各种方法。通过遵循我们的分步说明,您将能够监控您的密码到期日期并保持对您帐户的无缝访问。
为什么检查 Office 365 中的上次密码更改日期很重要
密码是防止未经授权访问您的 Office 365 帐户的第一道防线。如果您的密码落入坏人之手,您的数据就会面临风险。定期更改密码非常重要,并确保您的员工也这样做。检查 Office 365 中的上次密码更改日期可以帮助您识别潜在的安全风险,例如长时间未更改密码的员工。
此外,了解上次更改密码的时间可以帮助您解决帐户问题。例如,如果您在登录时遇到问题,了解上次更改密码的时间可以帮助您确定问题是否与您的密码有关。
在 Office 365 中检查上次密码更改日期的方法
在 Office 365 中检查上次密码更改日期有两种主要方法:Microsoft Graph PowerShell 和 Microsoft Online Services PowerShell 模块(Azure AD PowerShell 模块 V1)。这两种方法都相对易于使用,并且可以提供有关您帐户安全的有价值的信息。
要获取特定用户的上次密码更改日期,请使用以下 Microsoft Graph PowerShell 脚本:
#Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All"
#Get the User
$User = Get-MgUser -UserId "salaudeen@Crescent.com" -Property UserPrincipalName, PasswordPolicies, lastPasswordChangeDateTime
#Get the user's last password change date and time
$User | Select UserPrincipalName, PasswordPolicies, lastPasswordChangeDateTime
同样,要获取所有用户的上次密码更改日期时间戳,请使用以下 PowerShell 脚本:
#Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All"
#Retrieve the password change date timestamp of all users
Get-MgUser -All -Property UserPrincipalName, PasswordPolicies, lastPasswordChangeDateTime `
| Select -Property UserPrincipalName, PasswordPolicies, lastPasswordChangeDateTime
此信息对于需要监控用户帐户并确保其密码安全的管理员非常有帮助。要将所有用户的上次密码更改日期导出到 CSV 文件,请使用以下 PowerShell 脚本:
#Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All"
#Set the properties to retrieve
$Properties = @(
"id",
"DisplayName",
"userprincipalname",
"PasswordPolicies",
"lastPasswordChangeDateTime",
"mail",
"jobtitle",
"department"
)
#Retrieve the password change date timestamp of all users
$AllUsers = Get-MgUser -All -Property $Properties | Select -Property $Properties
#Export to CSV
$AllUsers | Export-Csv -Path "C:\Temp\PasswordChangeTimeStamp.csv" -NoTypeInformation
使用 MSOL PowerShell 模块获取 Office 365 中的上次密码更改日期
PowerShell 是一个功能强大的命令行工具,可用于管理 Office 365 的几乎所有方面。若要使用 PowerShell 获取 Office 365 中的上次密码更改日期,必须安装适用于 Windows PowerShell 的 Microsoft 在线服务 (MSOL) 模块。
使用 PowerShell 获取 Office 365 中上次密码更改日期的分步指南
- 安装适用于 Windows PowerShell 的 Microsoft Online Services PowerShell 模块:
Install-Module MSOnline - 打开 PowerShell 并通过运行以下命令连接到您的 Office 365 帐户:
Connect-MsolService - 出现提示时输入您的 Office 365 凭据。
- 使用以下命令获取特定用户的上次密码更改日期:
(Get-MsolUser -UserPrincipalName user@domain.com).LastPasswordChangeTimestamp。将“user@domain.com”替换为您要检查的用户的电子邮件地址。 - 最后一次密码更改日期将以 UTC 格式返回。
#Connect to Microsoft Online Service
Connect-MsolService
#Get the User
$user=Get-MsolUser -UserPrincipalName "salaudeen@Crescent.com"
#Get the last password change date
$user.LastPasswordChangeTimestamp
如何查看Office 365密码何时过期?
监控密码过期日期使您能够避免帐户锁定等中断,并保持对 Microsoft 365 应用程序的一致访问!以下是用于计算用户帐户的密码到期日期的 PowerShell 脚本:
#Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All"
#Get the User
$User = Get-MgUser -UserId "Salaudeen@crescent.com" -Property UserPrincipalName, lastPasswordChangeDateTime
#Get the user's password expiring date
$User.lastPasswordChangeDateTime.AddDays(90)
同样,使用 MSOL 模块,您可以获得密码到期日期,如下所示:
#Connect to Microsoft Online Service
Connect-MsolService
#Get the User
$user = Get-MsolUser -UserPrincipalName "salaudeen@crescent.com"
#Get the password Expiring date
$user.LastPasswordChangeTimestamp.AddDays(90)
该脚本根据用户上次更改密码和默认的 90 天密码过期策略来计算密码过期日期。如何查找 Office 365 租户中所有用户的密码到期日期?
#Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All"
#Set the properties to retrieve
$Properties = @(
"id",
"DisplayName",
"userprincipalname",
"PasswordPolicies",
"lastPasswordChangeDateTime",
"AccountEnabled",
"userType"
)
#Retrieve All users from Microsoft 365 and Filter
$AllUsers = Get-MgUser -All -Property $Properties | Select -Property $Properties | `
Where {$_.AccountEnabled -eq $true -and $_.PasswordPolicies -notcontains "DisablePasswordExpiration" -and $_.userType -ne "Guest"}
#Filter and Export data to CSV
$FilteredUsers = $AllUsers | Select Id, DisplayName, UserPrincipalName, @{Name="ExpiryDate";Expression={$_.lastPasswordChangeDateTime.AddDays(90)}}
$FilteredUsers
$FilteredUsers | Export-Csv -Path "C:\Temp\PasswordExpiryDate.csv" -NoTypeInformation
Write-host "Password Expiry Date for all users is exported!" -f Green
如何检查Office 365密码何时过期?
要获取特定用户帐户的密码到期日期,请使用以下 PowerShell 脚本:
#Parameter
$UserAccount = "Salaudeen@Crescent.com"
#Connect to Office 365 from PowerShell
Connect-MsolService
#Get the Default Domain
$Domain = Get-MsolDomain | where {$_.IsDefault -eq $true}
#Get the Password Policy
$PasswordPolicy = Get-MsolPasswordPolicy -DomainName $Domain.Name
#Get the User account
$UserAccount = Get-MsolUser -UserPrincipalName $UserAccount
#Get Password Expiry date
$PasswordExpirationDate = $UserAccount.LastPasswordChangeTimestamp.AddDays($PasswordPolicy.ValidityPeriod)
$PasswordExpirationDate
#Get the Password Expiring date
$UserAccount | Select LastPasswordChangeTimestamp, @{Name="Password Age";Expression={((Get-Date).ToUniversalTime())-$_.LastPasswordChangeTimeStamp}}
要获取使用 MSOL 模块的所有用户的密码到期日期,请使用以下脚本:
#Connect to Microsoft Online Service
Connect-MsolService
#Get all Users
$AllUsers = Get-MsolUser -All | Select ObjectId, DisplayName,UserPrincipalName, BlockCredential, UserType, @{Name="ExpiryDate";Expression={$_.LastPasswordChangeTimeStamp.AddDays(90)}}
#Filter users
$FilteredUsers = $AllUsers | Where {$_.PasswordNeverExpires -ne $true -and $_.UserType -ne "Guest" -and $_.BlockCredential -ne $true } | Select DisplayName,UserPrincipalName, ExpiryDate
$FilteredUsers
#Get the password Expiring date
$FilteredUsers | Export-Csv -Path "C:\Temp\PasswordExpiryDates.csv" -NoTypeInformation
结论和要点
总之,检查密码过期日期是一个简单的过程,可以为您节省时间并减少将来的麻烦。通过本文概述的方法,您可以轻松检查用户的上次密码更改日期,并采取措施提高密码安全性。请记住要求使用强密码、强制密码过期并教育您的员工密码安全的重要性。通过执行上述步骤,您可以轻松检查密码的到期日期并确保用户帐户的安全。
