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

[玩转系统] 使用 Microsoft Graph PowerShell 生成邮箱使用情况报告

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

使用 Microsoft Graph PowerShell 生成邮箱使用情况报告


Microsoft 365 中的使用情况报告(例如 OneDrive、SharePoint 和邮箱使用情况报告)是快速概览租户中存储利用率的便捷方法。 Microsoft 问答中提出的一个问题是,这些报告无法配置为在设定的时间段内通过电子邮件自动发送给您,特别是 Exchange Online 邮箱使用情况报告。

此问题的解决方案是首先使用 Microsoft Graph PowerShell 生成相同的报告。生成报告后,您可以灵活地通过电子邮件发送报告或将其放入文件共享中以供以后阅读。

在本博客中,我将向您展示如何使用 Microsoft Graph PowerShell 从 Microsoft 365 生成 Exchange Online 邮箱使用情况报告。

要求

  • 您必须安装最新的 Microsoft Graph PowerShell 模块。 了解如何安装 Microsoft Graph PowerShell 模块。
  • 您必须同意以下权限:Reports.Read.All这将需要一个全局管理员帐户。

Exchange Online 使用报告

下面是一个简短的脚本,它将为您组织中的所有 Exchange 在线邮箱生成邮箱使用情况报告。具体来说,此报告将突出显示每个邮箱使用的存储总量(以字节为单位),然后将该数字转换为兆字节以方便阅读。这在迁移场景或许可评估期间非常有用。尽管此报告中的期限不相关,但为了增加混乱,您仍然必须定义使用期限,即使它不会影响结果。

对于以下每个脚本,修改 $path 变量以匹配要将结果导出到的位置。

邮箱使用报告

Connect-MgGraph -scopes Reports.Read.All
$path = "C:\temp\MailboxReport.csv"
Get-MgReportMailboxUsageDetail -Period D7 -OutFile $path
$report = import-csv $path
$report.Foreach({
    $_."storage used (Byte)" = '{0:N2} MB' -f ($_."storage used (Byte)" / 1MB)
})
$report | Export-CSV -Path $path -NoTypeInformation

所有 Microsoft Graph PowerShell 使用情况报告 cmdlet

您可以使用 PowerShell 生成许多其他相关的 Microsoft 报告,其中一些可以使用使用期限,而有些则仍然不能。下面是所有可用的使用情况报告 cmdlet 的列表,分为几个部分。

打印
Get-MgReportDailyPrintUsageByPrinter
Get-MgReportDailyPrintUsageByPrinterCount
Get-MgReportDailyPrintUsageByUser
Get-MgReportDailyPrintUsageByUserCount
Get-MgReportMonthlyPrintUsageByPrinter
Get-MgReportMonthlyPrintUsageByPrinterCount
Get-MgReportMonthlyPrintUsageByUser
Get-MgReportMonthlyPrintUsageByUserCount

邮件
Get-MgReportEmailAppUsageAppUserCount
Get-MgReportEmailAppUsageUserCount
Get-MgReportEmailAppUsageUserDetail
Get-MgReportEmailAppUsageVersionUserCount
Get-MgReportMailboxUsageDetail
Get-MgReportMailboxUsageMailboxCount
Get-MgReportMailboxUsageQuotaStatusMailboxCount
Get-MgReportMailboxUsageStorage

OneDrive
Get-MgReportOneDriveUsageAccountCount
Get-MgReportOneDriveUsageAccountDetail
Get-MgReportOneDriveUsageFileCount
Get-MgReportOneDriveUsageStorage

SharePoint
Get-MgReportSharePointSiteUsageDetail
Get-MgReportSharePointSiteUsageFileCount
Get-MgReportSharePointSiteUsagePage
Get-MgReportSharePointSiteUsageSiteCount
Get-MgReportSharePointSiteUsageStorage

团队设备
Get-MgReportSkypeForBusinessDeviceUsageDistributionUserCount
Get-MgReportSkypeForBusinessDeviceUsageUserCount
Get-MgReportSkypeForBusinessDeviceUsageUserDetail
Get-MgReportTeamDeviceUsageDistributionUserCount
Get-MgReportTeamDeviceUsageUserCount
Get- MgReportTeamDeviceUsageUserDetail

Yammer
Get-MgReportYammerDeviceUsageDistributionUserCount
Get-MgReportYammerDeviceUsageUserCount

报告期

Microsoft Graph PowerShell 支持的报告周期与 Microsoft 365 管理中心支持的报告周期相匹配。以下是支持的使用期限(以天为单位):

  • D7
  • D30
  • D90
  • D180

通过电子邮件自动生成报告

每个报告都可以自动通过电子邮件发送到用户的邮箱、组或共享邮箱。为此,可以使用 Microsoft Graph 发送电子邮件,并使用 Microsoft Graph PowerShell 自动发送电子邮件。以下是我使用 Microsoft Graph PowerShell 发送邮件的代码示例:

(此 Send-MgUserMail cmdlet 位于 Microsoft.Graph.Users.Actions 模块中,需要获得 mail.send 权限)。 EM>

$Attachment = %filepath%
$MailAttachement = [Convert]::ToBase64String([IO.File]::ReadAllBytes($Attachment))

$body = @{
	message = @{
		subject = "Org Mailbox Report"
		body = @{
			contentType = "Text"
			content = "Please see the attached"
		}
		toRecipients = @(
			@{
				emailAddress = @{
					address = "%TO ADDRESS%"
				}
			}
		)
        attachments = @(
			@{
				"@odata.type" = "#microsoft.graph.fileAttachment"
				name = "$Attachment"
				contentType = "text/plain"
				contentBytes = $MailAttachement
			}
        )
	}
	saveToSentItems = "false"
}

Send-MgUserMail -UserId $from -BodyParameter $body

此过程可以使用 Azure 自动化实现自动化,以确保其安全运行,而不是从物理或虚拟服务器运行。我在博客如何使用 Azure 自动化运行 Microsoft Graph PowerShell 脚本中详细介绍了此过程。

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

取消回复欢迎 发表评论:

关灯