[玩转系统] Microsoft 365:密码过期通知电子邮件
作者:精品下载站 日期:2024-12-14 21:50:31 浏览:13 分类:玩电脑
Microsoft 365:密码过期通知电子邮件
密码过期通知在维护组织的 Microsoft 365 帐户的安全方面发挥着至关重要的作用。确保用户了解密码即将到期可以帮助防止帐户锁定并鼓励用户创建强而独特的密码。在本指南中,我们将演示如何创建 Microsoft Graph PowerShell 脚本,以便在用户的 Office 365 密码即将过期时自动向用户发送电子邮件通知。
什么是密码过期通知电子邮件?
密码过期通知电子邮件是当用户的密码即将过期时发送给用户的消息。该电子邮件通常包含有关密码到期日期的信息以及有关如何更改密码的说明。对于希望确保用户定期更改密码并确保帐户安全的组织来说,密码到期通知电子邮件是必不可少的工具。
如何在 Microsoft 365 中发送密码过期通知电子邮件?
由于 Microsoft 365 管理中心不再支持密码过期通知(可能是因为 Microsoft 建议禁用密码过期!),我们必须实施基于 Windows PowerShell 脚本的解决方案。要为 Office 365 密码过期通知创建 Microsoft Graph PowerShell 脚本,请执行以下步骤:
先决条件:安装 Microsoft Graph PowerShell 模块。您需要在计算机上安装 Microsoft Graph PowerShell 模块。使用:安装模块 Microsoft.Graph
。
使用此 PowerShell 脚本向密码即将过期的所有用户发送电子邮件提醒:
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All", "Mail.Send"
# Set the notification threshold - days before password expires
$NotificationThreshold = 7
$PasswordExpiryThreshold = 90 #By default 90 days Password expiry
# Get all users
$AllUsers = Get-MgUser -All -Property Id, DisplayName, UserPrincipalName,Mail,UserType, AccountEnabled,PasswordPolicies,lastPasswordChangeDateTime
# Iterate through each user
ForEach ($User in $AllUsers)
{
# Skip disabled accounts and users with Password never Expire flag
If (!$User.AccountEnabled -or $User.PasswordPolicies -contains "xDisablePasswordExpiration" -or $User.userType -eq "Guest") {
continue
}
# Get user's password Expiry Date
$PasswordExpiryDate = $User.lastPasswordChangeDateTime.AddDays($PasswordExpiryThreshold)
# Calculate the remaining days
$RemainingDays = ($PasswordExpiryDate - (Get-Date)).Days
# Check if the remaining days are within the notification threshold
If ($RemainingDays -le $NotificationThreshold) {
# Send an email notification to the user
$EmailBody = "
Hello $($User.DisplayName),
<br/><br/>
Your Office 365 password will expire in $remainingDays days. Please change your password before it expires to avoid any disruption in accessing your account.
<br/><br/>
To change your password, follow these steps:<br/>
<ol>
<li>Sign in to Office 365 (https://www.office.com)</li>
<li>Click on your profile picture in the top right corner.</li>
<li>Select 'View account'.</li>
<li> Click 'Password'.</li>
<li> Follow the instructions to change your password.</li>
</ol>
<br/>
Thank you,<br/>
IT Support Team
"
$MailParams = @{
Message = @{
Subject = "Your Office 365 password will expire soon"
Importance = "High"
Body = @{
ContentType = "html"
Content = $EmailBody
}
ToRecipients = @(
@{
EmailAddress = @{
Address = $User.Mail
}
}
)
}
}
# Send the email using Microsoft Graph
Send-MgUserMail -UserId $User.Mail -BodyParameter $MailParams
}
}
此脚本将提示输入登录凭据,并遍历组织中的所有用户,计算密码到期日期,并向密码将在指定阈值(在我们的示例中为 7 天)内到期的用户发送电子邮件通知。您可以修改 $NotificationThreshold
变量来调整发送通知时密码到期前的天数。
这是正在运行的脚本:
自动发送密码到期提醒电子邮件
对于无人值守的自动化场景,请按照以下步骤操作:
第1步:创建App ID并授予权限
在 Azure AD 中创建应用 ID 以与 Microsoft Graph 连接:如何连接到 Microsoft Graph PowerShell 模块?确保您向 App ID 授予“User.Read.All”和“Mail.Send”权限。
步骤 2:更新此 PowerShell 脚本中的参数
准备好应用程序 ID 后,更新此 PowerShell 脚本的参数部分。该脚本的工作原理如下:
- 使用给定的应用程序 ID 和证书指纹连接到 Microsoft Graph
- 检查所有用户的密码过期日期 - 排除密码永不过期、密码已过期、访客用户等用户。
- 从给定的电子邮件 ID 向密码在给定阈值(脚本中为 15 天!)内过期的用户发送电子邮件(确保您已创建电子邮件。例如,在我们的示例中,它是:$SenderID=“Helpdesk@ Crescent.com”)。
- 将消息记录到日志文件中。
#Parameters
$TenantID = "c1c2b123-4240-4775-a19a-6351b30cx2f6"
$ClientID = "3c1541f7-9565-4abe-b398-f47ac91c2c06" #App ID
$CertThumbPrint = "63FDDD207DE01C0EB34C35647D086D3C1520FA7"
#Path for Log File
$LogFilePath = "C:\Scripts\PasswordExpiry.Log"
$SenderID = "[email protected]"
#Notification threshold - days before password expires
$NotificationThreshold = 15
$PasswordExpiryThreshold = 90 #By default 90 days Password expiry
#Function to Add Content to a Log File
Function Write-Log {
[CmdletBinding()]
Param ([Parameter(Mandatory=$true)][string]$Message)
Process{
#Add Message to Log File with timestamp
"$([datetime]::Now) : $Message" | Out-File -FilePath $LogFilePath -append;
#Write the log message to the screen
Write-host $([datetime]::Now) $Message
}
}
#Connect to Microsoft Graph using App
Connect-MgGraph -ClientID $ClientID -TenantId $TenantID -CertificateThumbprint $CertThumbPrint
#Ensure the Parent Folder for Log File
$FolderPath= Split-Path $LogFilePath
If(!(Test-Path -path $FolderPath)) {
New-Item -ItemType directory -Path $FolderPath | Out-Null
}
# Get all users
$AllUsers = Get-MgUser -All -Property Id, DisplayName, UserPrincipalName,Mail,UserType, AccountEnabled,PasswordPolicies,lastPasswordChangeDateTime
# Iterate through each user
ForEach ($User in $AllUsers)
{
# Skip disabled accounts and users with Password never Expire flag
If (!$User.AccountEnabled -or $User.PasswordPolicies -contains "DisablePasswordExpiration" -or $User.userType -eq "Guest") {
continue
}
# Get user's password Expiry Date
$PasswordExpiryDate = $User.lastPasswordChangeDateTime.AddDays($PasswordExpiryThreshold)
# Calculate the remaining days
$RemainingDays = ($PasswordExpiryDate - (Get-Date)).Days
# Check if the remaining days are within the notification threshold
If ($RemainingDays -le $NotificationThreshold -and $RemainingDays -ge 0) {
# Send an email notification to the user
$EmailBody = "
Hello $($User.DisplayName),
<br/><br/>
Your Office 365 password will expire in $remainingDays days. Please change your password before it expires to avoid any disruption in accessing your account.
<br/><br/>
To change your password, follow these steps:<br/>
<ol>
<li>Sign in to Office 365 (https://www.office.com)</li>
<li>Click on your profile picture in the top right corner.</li>
<li>Select 'View account'.</li>
<li> Click 'Password'.</li>
<li> Follow the instructions to change your password.</li>
</ol>
<br/>
Thank you,<br/>
IT Support Team
"
$MailParams = @{
Message = @{
Subject = "Your Office 365 password will expire soon"
Importance = "High"
Body = @{
ContentType = "html"
Content = $EmailBody
}
ToRecipients = @(
@{
EmailAddress = @{
Address = $User.Mail
}
}
)
}
}
# Send the email using Microsoft Graph
Send-MgUserMail -UserId $SenderID -BodyParameter $MailParams
#Write to Log File
Write-Log "Password Expiration Notification sent to user $($User.Mail) - Password Expires on $PasswordExpiryDate"
}
}
该脚本可以极大地节省生产力,因为如果没有适当的通知,用户可能会在密码过期时措手不及,从而导致帐户锁定和生产力中断。这些电子邮件将通知用户他们的密码即将过期,应更改密码以避免任何中断。
步骤 3:安排 PowerShell 脚本
您可以创建一个自动化系统,用于向 Office 365 用户发送密码过期通知电子邮件:使用 Windows 任务计划程序计划 PowerShell 脚本或使用 Azure Runbook 自动执行 PowerShell。
通过遵循我们的分步说明,您将能够帮助用户随时了解其密码到期日期并保持对其 Office 365 帐户的安全访问。
密码过期通知电子邮件的最佳实践
以下是组织在实施密码过期通知电子邮件时应遵循的一些最佳实践:
- 确保用户在密码到期日期之前收到通知电子邮件。这将使他们有足够的时间更改密码,而不会中断他们的工作。
- 提供有关如何更改密码的明确说明。包含用户可用来更改密码的资源链接。
- 鼓励用户创建难以猜测或破解的强而复杂的密码。
- 考虑实施多重身份验证,为用户帐户添加额外的安全层。
- 定期检查您的密码政策,以确保其是最新的并符合行业最佳实践。
结论:
使用用于 Office 365 密码过期通知的 Microsoft Graph PowerShell 脚本,您可以自动执行提醒用户在密码过期之前更新密码的过程。这种主动方法可以帮助用户随时了解其密码到期日期,降低帐户锁定的风险,并为您的组织营造一个安全的环境。实施此 Microsoft Graph PowerShell 解决方案可以增强组织的安全性并保持对 Office 365 资源的无缝访问,同时为所有用户提供安全的环境。
经常问的问题:
如何设置Office 365账户密码永不过期?
要将 Office 365 用户帐户的密码设置为永不过期,可以使用 Azure Active Directory PowerShell 或 Microsoft Graph API PowerShell cmdlet。您还可以通过 Office 365 管理中心中的密码过期策略禁用组织的密码过期(设置 >> 然后单击“组织设置”>>“安全和隐私”>> 选择密码过期策略 >> 选中旁边的框“将用户密码设置为永不过期”)。
详细信息:在 Office 365 中禁用密码过期
Office 365 是否会发送密码过期电子邮件?
Microsoft 365 不再支持密码过期通知!因此,您必须设置解决方法来向用户发送密码过期电子邮件。
Office 365 中的默认密码过期时间是多少?
自上次密码更改日期起 90 天(默认情况下禁用)。但是,全局管理员可以通过 Office 365 管理中心或 PowerShell 配置密码过期时间以满足组织的安全要求。
O365 密码过期后会发生什么?
当 Office 365 当前密码过期时,系统将提示用户在下次登录时更改密码。如果用户在实际过期日期后忽略提示并且不更改密码,他们的帐户将被锁定,直到他们重置了密码(管理员级别的技术支持可以解锁它)。但是,Outlook 等 Microsoft Office 应用程序可能会继续工作,直到缓存中的密码过期。
不再建议密码过期吗?
是的!不再建议将密码过期作为安全措施,因为它弊大于利。每 90 天更改一次密码可能会使黑客/诈骗者/网络犯罪分子在长达三个月内可以使用暴露的弱/旧密码,并且最好要求强密码并使用多重身份验证。
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag