[玩转系统] 如何在 Microsoft Entra 中报告用户同意的应用程序权限
作者:精品下载站 日期:2024-12-14 06:39:36 浏览:12 分类:玩电脑
如何在 Microsoft Entra 中报告用户同意的应用程序权限
默认情况下,组织中的用户可以授权应用程序访问 Microsoft Entra 中有关其自身的数据。不仅如此,默认情况下,用户还可以授权应用程序代表他们执行操作,例如创建 Microsoft Teams 并以所述用户的身份发送电子邮件。
在 99% 的场景中,不需要应用程序的此要求,除非应用程序是为非常自定义的工作流程创建的,其中管理员仍应配置为手动授予同意(或者再次通过特定工作流程)。
作为管理员,您应该限制用户可以自行授予应用程序访问权限的权限。这仍然应该仔细审查并与应用程序的要求保持一致。虽然我的单独帖子中对此进行了介绍,但在本文中,我将向您展示如何生成租户中应用程序的用户同意权限报告,然后将其导出到 CSV。
要求
本教程使用 Microsoft Graph PowerShell SDK。如果您尚未安装它,或者安装它已经有一段时间了,请查看我的帖子以指导您安装和更新模块。如何安装 Microsoft Graph PowerShell SDK。
您还需要访问租户中的全局管理员帐户。这样您就可以向 Microsoft Graph 命令行工具应用程序授予启动租户范围的权限。
用户同意的权限报告脚本
您可以复制以下脚本并根据您的喜好进行修改,也可以按原样运行它并生成报告。
该脚本利用批处理请求来提高检查 Microsoft Entra 中近 500 个服务主体的权限的性能。然后,它将过滤掉在用户级别同意的任何权限授予。
由于此用户授权信息不包含用户的用户名或应用程序名称,因此脚本将循环遍历每个对象 ID 以获取有意义的名称并将其添加到名为 $final 的报告中。
然后,系统将提示您选择导出和保存报告的位置。
在我的公共 GitHub 存储库中找到此脚本。
<#
.SYNOPSIS
Generates a report of user-consented permissions to application in Microsoft Entra
.LINK
https://ourcloudnetwork.com
https://www.linkedin.com/in/danielbradley2/
.NOTES
Version: 0.1
Author: Daniel Bradley
Creation Date: Monday, January 8th 2024, 6:54:33 am
File: ApplicationUserConsentReport.ps1
Copyright (c) 2024 Your Company
HISTORY:
2024-01-08 File Generated
.INPUTS
.OUTPUTS
.COMPONENT
Required Modules:
Microsoft.Graph.Applications
Microsoft.Graph.Users
.EXAMPLE
.\ApplicationUserConsentReport.ps1
.LICENSE
Use this code free of charge at your own risk.
Never deploy code into production if you do not know what it does.
#>
#Connect to graph
Connect-MgGraph -Scopes Application.Read.All, user.read.all
#Define output file name
$filename = "User_Permissions_Grant_Report.csv"
#Function will launch Windows explorer to select a folder
Function SelectFolder {
$global:folderselection = New-Object System.Windows.Forms.OpenFileDialog -Property @{
InitialDirectory = [Environment]::GetFolderPath('Desktop')
CheckFileExists = 0
ValidateNames = 0
FileName = $filename
}
$folderselection.ShowDialog() | Out-Null
}
#Gets all service principals with limited info
Write-host "Gathering service principals.." -ForegroundColor Yellow
$AllServicePrincipals = Get-MgServicePrincipal -All | Select Id, appid, DisplayName
#Send batch requests to gather all user grants, due to large number of service principals
Write-host "Indentifying user grants..." -ForegroundColor Yellow
$Report = @()
for($i=0;$i -lt $AllServicePrincipals.count;$i+=20){
$batch = @{}
$batch['requests'] = ($AllServicePrincipals[$i..($i+19)] | select @{n='id';e={$_.id}},@{n='method';e={'GET'}},`
@{n='url';e={"/servicePrincipals/$($_.id)/oauth2PermissionGrants"}})
$response = invoke-mggraphrequest -Method POST -URI "https://graph.microsoft.com/v1.0/`$batch" -body ($batch | convertto-json) -OutputType PSObject
$Report += $response.responses
}
$UserGrants = $Report.body.value | Where {$_.ConsentType -eq "Principal"}
#Uses loop function to gather additional information such as the userprincipalname. It also correlates the service principal name.
Write-host "correlating information..." -ForegroundColor Yellow
$final = [System.Collections.Generic.List[Object]]::new()
Foreach ($Grant in $UserGrants){
$user = $null
$app = $null
$user = Get-MgUser -UserId $Grant.principalId | Select UserPrincipalName
$app = $AllServicePrincipals | Where {$_.id -eq $($grant.clientid)}
$obj = [PSCustomObject][ordered]@{
"Application" = $app.DisplayName
"user" = $user.UserPrincipalName
"permission" = ($grant.scope.Trim() -replace " ",", ")
}
$final.Add($obj)
}
#Run select folder function
Write-host "Please select a folder `n" -ForegroundColor Green
Start-Sleep -Seconds 2
SelectFolder
#Export file
$final | Export-CSV -Path $folderselection.FileName -NoTypeInformation
Write-host "File saved! Click Enter to close... `n" -ForegroundColor Green
Write-host " Script by >> Daniel Bradley " -ForegroundColor cyan -BackgroundColor black
Write-host " Visit >> ourcloudnetwork.com " -ForegroundColor cyan -BackgroundColor black
Write-host " Connect >> https://www.linkedin.com/in/danielbradley2/ " -ForegroundColor cyan -BackgroundColor black
Write-host "`n"
Pause
脚本运行后,您将收到如下所示的报告。
包起来
收回对环境中应用程序的控制非常重要。即使您阻止用户在租户中创建应用程序并限制应用程序用户同意,应用程序中也可能潜伏着一些权限,此脚本将帮助您找到这些权限!
猜你还喜欢
- 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