当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 给管理员使用 Microsoft Graph PowerShell 的 5 个重要提示

作者:精品下载站 日期:2024-12-14 06:52:21 浏览:15 分类:玩电脑

给管理员使用 Microsoft Graph PowerShell 的 5 个重要提示


与您所习惯的相比,Microsoft Graph Explorer 可能发生了很大的变化,这不仅是因为新的命令和功能集,而且还因为您需要遵循的流程来确保您快速高效地工作。

以下是我提供的 5 条重要提示,可确保您更好地使用 Microsoft Graph PowerShell!

了解并创建同意流程

尽管 Microsoft Graph PowerShell 背后的核心机制与其前身相同,但对于管理员来说,应该区别对待并小心对待。在幕后,当您从 Microsoft Graph PowerShell 模块运行命令时,会调用 Graph API,然后与相关的 Microsoft 服务(在大多数情况下是 Microsoft Entra)进行交互。对于遗留模块也是如此,只是与不同的 API 进行交互。

对于像你我这样的管理员,需要对 Microsoft Graph PowerShell 模块进行额外的安全考虑,例如考虑需要全局管理员或特权角色管理员在运行特定命令之前同意服务主体的权限。

例如,以前具有用户管理员角色的管理员可以连接到旧模块并修改用户而无需额外帮助,而现在,如果同一用户管理员连接到 Microsoft Graph PowerShell,则未经全局管理员明确同意,他们无法执行任何任务。您不希望特权用户出于方便而被分配全局管理员权限,这取决于您作为全局管理员来确保提供方便高效的解决方案。

您应该投入一些时间和精力来确保拥有高效的权限同意批准流程,以便在分配权限之前仔细审查权限。

使用专用帐户来使用 Microsoft Graph PowerShell

Microsoft Graph 是一个功能强大的工具,再加上 PowerShell SDK 和过度劳累的管理员,如果没有得到适当的保护,它也可能是一个危险的工具。

使用 Microsoft Graph PowerShell 时,请使用专用用户帐户,然后将该帐户直接分配给您在连接到 Microsoft Graph PowerShell 时进行身份验证的服务主体。

[玩转系统] 给管理员使用 Microsoft Graph PowerShell 的 5 个重要提示

此步骤可能看起来有些过大,但一旦组织中的帐户遭到破坏,攻击者尝试枚举他们可以渗透的内容的第一个也是最快的方法是通过代码,并且很可能使用 Microsoft Graph。

使用专用帐户可以为您的组织带来诸多安全优势,例如:

  • 通过选择具有增强安全性的“所有云应用程序”,例如基于位置的访问、会话策略和更强的身份验证,能够通过条件访问来确保安全。
  • 允许您使用对服务主体的直接分配来轻松管理谁可以使用 Microsoft Graph PowerShell。
  • 限制违规的可能性,因为该帐户仅用于该特定任务。
  • 以及更多!

了解 HTTP 请求的工作原理

每次使用 Microsoft Graph PowerShell 模块运行命令时,都会使用 GET、POST、PUT、PATCH 或 DELETE 方法将 HTTP 请求发送到 Graph API,具体取决于您运行的命令。

为了演示这些 HTTP 请求是自动发生的,您可以使用 -debug 参数来显示正在请求的 HTTP URL,例如,我在这里运行 Get-MgUser cmdlet 用于检索我的组织中所有用户的列表。

[玩转系统] 给管理员使用 Microsoft Graph PowerShell 的 5 个重要提示

您可以看到我们立即在控制台窗口中获得了一些调试内容。请注意绝对 Uri,这是发送到 Microsoft Graph 的确切 HTTP 请求。当我们检索或下载信息时,HTTP 方法还会显示GET

这是我检索特定用户信息的另一个示例。请注意,绝对 Uri 与我检索所有用户信息的位置不同,它现在显示我们在 URL 中请求的特定用户。

[玩转系统] 给管理员使用 Microsoft Graph PowerShell 的 5 个重要提示

通过了解每个命令基本上都与特定的 HTTP 请求相关,您将在调试脚本、阅读文档和识别权限时获得更好的体验。

您的浏览器开发工具是您找出正确命令的朋友

您是否曾经遇到过这样的情况:您需要使用 PowerShell 更改环境,但文档并不清楚要运行哪个命令或如何格式化您的负载……您最喜欢的 Web 浏览器中的内置开发人员工具可以提供帮助你解决这个问题。

例如,我希望阻止组织中的标准用户将新设备加入 Microsoft Entra ID,但该任务的命令可能是可用的数千个命令之一。

我可以通过 Microsoft Entra 管理中心进行所需的更改来简化此调查过程,然后在浏览器中打开网络开发人员工具,我可以看到正在发出什么请求。

[玩转系统] 给管理员使用 Microsoft Graph PowerShell 的 5 个重要提示

在此示例中,发出以下请求:

  • URI: https://graph.microsoft.com/beta/policies/deviceRegistrationPolicy
  • 方法: PUT

现在我们有了这些信息,推断等效 PowerShell 命令的最快方法是将 URI 粘贴到 Google 搜索中并查找该 API 的相关 Microsoft Learn 文档:

[玩转系统] 给管理员使用 Microsoft Graph PowerShell 的 5 个重要提示

在大多数情况下,Microsoft 将提供可用的 PowerShell 示例:

[玩转系统] 给管理员使用 Microsoft Graph PowerShell 的 5 个重要提示

当您知道在哪里可以找到权限时,权限就很容易获得

使用 Microsoft Graph PowerShell 肯定会遇到一些额外的挑战,例如新的命名约定、新的和有限的功能以及响应结构,但最重要的学习曲线之一是了解您之前需要同意哪些权限你运行一个脚本。

您应该了解如何以及在哪里找到运行脚本所需的正确权限,因为不正确的权限可能会让您的组织面临额外的风险。

下面是一个示例:作为帮助台职责的一部分,用户需要不断更改用户属性,并且需要决定哪些权限最适合他的需求。他运行以下命令来查找该信息:

(Find-MgGraphCommand Update-MgUser).permissions

输出如下所示:

Name                                         IsAdmin Description                                                       FullDescription
----                                         ------- -----------                                                       ---------------
DeviceManagementApps.ReadWrite.All           True    Read and write Microsoft Intune apps                              Allows the app to read and write the properties, group assignments and status of apps, app configurations and app protection policies managed by Microsoft Intune.
DeviceManagementConfiguration.ReadWrite.All  True    Read and write Microsoft Intune Device Configuration and Policies Allows the app to read and write properties of Microsoft Intune-managed device configuration and device compliance policies and their assignment to groups.
DeviceManagementManagedDevices.ReadWrite.All True    Read and write Microsoft Intune devices                           Allows the app to read and write the properties of devices managed by Microsoft Intune. Does not allow high impact operations such as remote wipe and password reset on the device’s owner.
DeviceManagementServiceConfig.ReadWrite.All  True    Read and write Microsoft Intune configuration                     Allows the app to read and write Microsoft Intune service properties including device enrollment and third party service connection configuration.
Directory.ReadWrite.All                      True    Read and write directory data                                     Allows the app to read and write data in your organization's directory, such as other users, groups.  It does not allow the app to delete users or groups, or reset user passwords.
User.EnableDisableAccount.All                True    Enable and disable user accounts                                  Allows the app to enable and disable users' accounts, on your behalf.
User.ManageIdentities.All                    True    Manage  user identities                                           Allows the app to read, update and delete identities that are associated with a user's account that you have access to. This controls the identities users can sign-in with.
User.ReadWrite                               False   Read and update your profile                                      Allows the app to read your profile, and discover your group membership, reports and manager. It also allows the app to update your profile information on your behalf.
User.ReadWrite.All                           False   Read and write all users' full profiles                           Allows the app to read and update user profiles without a signed in user.

虽然所有权限都允许至少更新某些用户属性,但其他权限还允许修改的不仅仅是用户属性。此处选择的正确权限是User.ReadWrite.All。如果选择了 Directory.ReadWrite.All 权限,则该任务将变得权限过高,这可能会导致数据意外丢失或被利用。

使用 Microsoft Graph Explorer Web 工具是一种更友好的读取权限方法。使用此工具,您可以搜索代码示例以及您运行的命令所需的权限。使用修改权限选项卡查找您刚刚使用 PowerShell 看到的相同信息。

[玩转系统] 给管理员使用 Microsoft Graph PowerShell 的 5 个重要提示

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯