[玩转系统] 导出 Microsoft 365 用户密码报告
作者:精品下载站 日期:2024-12-14 05:49:40 浏览:16 分类:玩电脑
导出 Microsoft 365 用户密码报告
您可以在 Microsoft 365 管理中心检查整个组织的密码过期策略。它不显示所有个人用户的列表。若要获取每个 Microsoft 365 用户的详细密码信息,您需要运行 PowerShell 脚本。在本文中,您将了解如何将 Microsoft 365 用户密码报告导出到 CSV 文件。
信息导出 Microsoft 365 用户密码 PowerShell 脚本
如果您的组织尚未设置密码过期策略,Microsoft 建议将密码设置为永不过期。当整个组织都有密码过期策略时,仍然可能有个别 Microsoft 365 用户使用其他策略。这就是 PowerShell 脚本可以发挥作用的地方。
该脚本将运行并收集每个用户的以下信息:
- ID
- 用户主体名称
- 邮件
- 显示名称
- 密码政策
- 上次密码更改日期时间
- 创建日期时间
- 领域
- 密码最长使用期限
- 密码年龄
- 到期
- 剩余天数
我们将在接下来的步骤中向您展示如何获得这些结果。
使用 PowerShell 将 Microsoft 365 用户导出为 CSV
让我们完成这些步骤并使用 PowerShell 将 Microsoft 365 用户密码报告导出到 CSV 文件。
1.安装Microsoft Graph PowerShell
在运行 Export-M365PasswordReport.ps1 PowerShell 脚本之前,您需要安装 Microsoft Graph PowerShell 模块。
运行以下命令来安装 Microsoft Graph 模块。
Install-Module Microsoft.Graph -Force
2. 连接到 Microsoft Graph PowerShell
您需要使用以下范围连接到 MS Graph。
Connect-MgGraph -Scopes "User.ReadWrite.All", "Group.ReadWrite.All", "Directory.ReadWrite.All"
- 使用您的管理员凭据登录
- 启用代表您的组织同意
- 点击接受
3.下载Export-M365PasswordReport PowerShell脚本
要下载 Export-M365PasswordReport PowerShell 脚本,请执行以下步骤:
- 下载 Export-M365PasswordReport.ps1 PowerShell 脚本
- 或者将以下脚本复制到记事本中并将其另存为 Export-M365PasswordReport.ps1 文件
<#
.SYNOPSIS
.\Export-M365UsersPassword.ps1
.DESCRIPTION
Connect to Microsoft Graph PowerShell first.
The script exports the passwords report for all Microsoft 365 users to a CSV file.
.LINK
Export Microsoft 365 users password report
.NOTES
Written By: o365info
Website: o365info.com
.CHANGELOG
V1.00, 10/26/2023 - Initial version
#>
# Get all domain password expiration policies
$domains = Get-MgDomain | Select-Object Id, PasswordValidityPeriodInDays
$domains | ForEach-Object { if (!$_.PasswordValidityPeriodInDays) { $_.PasswordValidityPeriodInDays = 90 } }
# Get user information
$properties = "Id", "UserPrincipalName", "mail", "displayName", "PasswordPolicies", "LastPasswordChangeDateTime", "CreatedDateTime"
$users = Get-MgUser -Filter "userType eq 'member' and accountEnabled eq true" `
-Property $properties -CountVariable userCount `
-ConsistencyLevel Eventual -All -Verbose | `
Select-Object $properties | Where-Object {
"$(($_.userPrincipalName).Split('@')[1])" -in $($domains.id)
}
# Add properties to the $users objects
$users | Add-Member -MemberType NoteProperty -Name Domain -Value $null
$users | Add-Member -MemberType NoteProperty -Name MaxPasswordAge -Value 0
$users | Add-Member -MemberType NoteProperty -Name PasswordAge -Value 0
$users | Add-Member -MemberType NoteProperty -Name ExpiresOn -Value (Get-Date '1970-01-01')
$users | Add-Member -MemberType NoteProperty -Name DaysRemaining -Value 0
# Get the current datetime for calculation
$timeNow = Get-Date
foreach ($user in $users) {
# Get the user's domain
$userDomain = ($user.userPrincipalName).Split('@')[1]
# Check if the user has "disablepasswordexpiration" set
if ($user.PasswordPolicies -contains "DisablePasswordExpiration") {
# Set values to indicate that the password does not expire for this user
$passwordAge = (New-TimeSpan -Start $user.LastPasswordChangeDateTime -End $timeNow).Days
$user.MaxPasswordAge = "Password does not expire"
$user.PasswordAge = $passwordAge
$user.ExpiresOn = "N/A"
$user.DaysRemaining = "N/A"
}
else {
# Get the maximum password age based on the domain password policy
$maxPasswordAge = ($domains | Where-Object { $_.id -eq $userDomain }).PasswordValidityPeriodInDays
# Check if MaxPasswordAge is 2147483647
if ($maxPasswordAge -eq 2147483647) {
$passwordAge = (New-TimeSpan -Start $user.LastPasswordChangeDateTime -End $timeNow).Days
$user.MaxPasswordAge = "Password does not expire"
$user.PasswordAge = $passwordAge
$user.ExpiresOn = "N/A"
$user.DaysRemaining = "N/A"
}
else {
$passwordAge = (New-TimeSpan -Start $user.LastPasswordChangeDateTime -End $timeNow).Days
$expiresOn = (Get-Date $user.LastPasswordChangeDateTime).AddDays($maxPasswordAge)
$user.PasswordAge = $passwordAge
$user.ExpiresOn = $expiresOn
$user.DaysRemaining = $(
# If the remaining days is negative, show "Expired" instead
if (($daysRemaining = (New-TimeSpan -Start $timeNow -End $expiresOn).Days) -le 0) { "Expired" }
else { $daysRemaining }
)
$user.MaxPasswordAge = $maxPasswordAge
}
}
$user.Domain = $userDomain
}
# Display the results in Out-GridView
$users | Out-GridView
# Export the results to CSV file
$users | Export-Csv -Path "C:\temp\M365UsersPassword.csv" -NoTypeInformation -Encoding UTF8
- 如果您还没有 (C:) 驱动器中的 scripts 和 temp 文件夹,请创建它们
- 将 Export-M365PasswordReport.ps1 PowerShell 脚本保存在 C:\scripts 文件夹中
打开文件检查是否已解锁,防止运行脚本时出错。
4. 运行 Export-M365PasswordReport PowerShell 脚本
以管理员身份运行 PowerShell 并运行 Export-M365PasswordReport.ps1 PowerShell 脚本。
C:\scripts\.\Export-M365PasswordReport.ps1
PowerShell 脚本开始扫描组织中的所有 Microsoft 365 用户。如果您有很多用户,可能需要几分钟的时间。
5. Out-GridView Microsoft 365 用户密码过期报告
该脚本将在网格视图窗口中显示 Microsoft 365 用户密码信息列表。
Out-GridView 在脚本完成后出现。它显示每个 Microsoft 365 用户拥有的密码策略(无、空、DisableStrongPassword 或 DisablePasswordExpiration)。
6. 在 Excel 中打开 Microsoft 365 用户密码过期报告 CSV 文件
您将在 C:\temp 文件夹中找到 M365UsersPassword.csv 文件。
使用 Microsoft Excel 等应用程序打开 CSV 文件以查看结果。
就是这样。
注意:现在您已拥有 Microsoft 365 用户密码报告,您可以管理 Microsoft 365 用户密码。
了解更多:使用 PowerShell 导出 Microsoft 365 邮箱大小报告 »
结论
您了解了如何使用 PowerShell 将 Microsoft 365 用户密码报告导出到 Out-GridView 和 CSV 文件。 Export-M365PasswordReport.ps1 PowerShell 脚本显示每个用户的详细密码报告。您将获得结构化概览,显示每个用户拥有哪些密码策略以及密码何时过期。
您喜欢这篇文章吗?您可能还喜欢导出 Microsoft 365 用户许可证。不要忘记关注我们并分享这篇文章
猜你还喜欢
- 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