Microsoft 365中的Export OnEdrive用法報告

用戶可以在其OneDrive存儲中佔用很多空間。借助OneDrive尺寸報告,您可以看到哪些用戶幾乎達到了極限。然後,您可以升級OneDrive存儲或告訴他們清理。在本文中,您將學習如何在Microsoft 365中導出OneDrive用法報告。

要在Microsoft 365中為用戶提供OneDrive存儲大小,請按照以下步驟操作:

  1. 登錄到Microsoft 365管理中心
  2. 點擊用戶>活動用戶
  3. 單擊用戶從列表中
  1. 點擊OneDrive
  2. 檢查使用的存儲部分

優勢在於,OneDrive存儲使用的數據在幾分鐘之內就填充了。

Microsoft 365 Admin Center中的Export OneDrive用法報告

要為Microsoft 365中的所有用戶導出OnEdrive用法報告,請按照以下步驟:

  1. 登錄到Microsoft 365管理中心
  2. 點擊設置> org設置>服務
  1. 點擊報告
  2. 取消選中在所有報告中顯示隱藏的用戶,組和站點名稱
  3. 點擊節省
  1. 點擊報告>用法
  2. 點擊OneDrive然後向下滾動到底部
  3. 點擊出口要下載OneDrive用法報告CSV文件

該報告的缺點是數據不是立即最新的。報告在48小時內可用。

帶有PowerShell腳本的出口OnEdrive用法報告

Got-onedriversizereport.ps1 PowerShell腳本將為所有用戶提供OneDrive大小,並輸出以下信息:

  1. 所有者
  2. UPN
  3. 站點
  4. ISDEATED
  5. 最後一個
  6. filecount
  7. ActiveFileCount
  8. 航程
  9. 二手GB
  10. 百分比
  11. 城市
  12. 國家
  13. 部門
  14. 職稱

筆記:腳本檢查組織中的報告中隱藏的用戶數據是否已啟用。如果是這樣,它會暫時禁用它,一旦報告完成,它將再次實現。

要向所有具有PowerShell的用戶導出ONEDRIVE使用報告,請按照以下步驟:

步驟1。安裝Microsoft Graph PowerShell

運行Windows PowerShell作為管理員並安裝Microsoft Graph PowerShell。

Install-Module Microsoft.Graph -Force

重要的:在運行CMDLET或腳本以防止錯誤和錯誤結果之前,請務必更新到最新的Microsoft Graph PowerShell模塊版本。

步驟2。下載Get-onedriversizereport PowerShell腳本

(c :)駕駛:

  • 腳本
  • 溫度

下載並將Get-onedrivesizereport.ps1 PowerShell腳本放在C:腳本文件夾。腳本將將所有用戶大小導出到報告中的報告C:溫度文件夾。

確保文件未阻止以防止運行腳本時的錯誤。在運行PowerShell腳本時,請在文章中閱讀更多信息。

另請閱讀:導出Microsoft 365管理員角色成員報告

另一個選擇是將下面的代碼複製並粘貼到記事本中。給它名字Get-onedrivesizereport.ps1並將其放在C:腳本文件夾。

<#
    .SYNOPSIS
    Get-OneDriveSizeReport.ps1

    .DESCRIPTION
    Export OneDrive storage usage in Microsoft 365 to CSV file with PowerShell.

    .LINK
    www.alitajran.com/export-onedrive-usage-report/

    .NOTES
    Written by: ALI TAJRAN
    Website:    www.alitajran.com
    LinkedIn:   linkedin.com/in/alitajran

    .CHANGELOG
    V1.00, 08/10/2024 - Initial version
#>

# Connect to Microsoft Graph with necessary permissions
Connect-MgGraph -NoWelcome -Scopes "User.Read.All", "Reports.Read.All", "ReportSettings.ReadWrite.All"

# Define file paths
$CSVOutputFile = "C:tempOneDriveSizeReport.csv"
$TempExportFile = "C:tempTempExportFile.csv"

# Remove the temporary export file if it exists
if (Test-Path $TempExportFile) {
    Remove-Item $TempExportFile
}

# Check if tenant reports have concealed user data, and adjust settings if necessary
if ((Get-MgAdminReportSetting).DisplayConcealedNames -eq $true) {
    $Parameters = @{ displayConcealedNames = $false }
    Write-Host "Unhiding concealed report data to retrieve full user information..." -ForegroundColor Cyan
    Update-MgAdminReportSetting -BodyParameter $Parameters
    $ConcealedFlag = $true
}
else {
    $ConcealedFlag = $false
    Write-Host "User data is already fully visible in the reports." -ForegroundColor Cyan
}

# Retrieve detailed user account information
Write-Host "Fetching user account details from Microsoft Graph..." -ForegroundColor Cyan

# Define user properties to be retrieved
$Properties = 'Id', 'displayName', 'userPrincipalName', 'city', 'country', 'department', 'jobTitle', 'officeLocation'

# Define parameters for retrieving users with assigned licenses
$userParams = @{
    All              = $true
    Filter           = "assignedLicenses/`$count ne 0 and userType eq 'Member'"
    ConsistencyLevel = 'Eventual'
    CountVariable    = 'UserCount'
    Sort             = 'displayName'
}

# Get user account information and select the desired properties
$Users = Get-MgUser @UserParams -Property $Properties | Select-Object -Property $Properties

# Create a hashtable to map UPNs (User Principal Names) to user details
$UserHash = @{}
foreach ($User in $Users) {
    $UserHash[$User.userPrincipalName] = $User
}

# Retrieve OneDrive for Business site usage details for the last 30 days and export to a temporary CSV file
Write-Host "Retrieving OneDrive for Business site usage details..." -ForegroundColor Cyan
Get-MgReportOneDriveUsageAccountDetail -Period D30 -Outfile $TempExportFile

# Import the data from the temporary CSV file
$ODFBSites = Import-CSV $TempExportFile | Sort-Object 'User display name'

if (-not $ODFBSites) {
    Write-Host "No OneDrive sites found." -ForegroundColor Yellow
    return
}

# Calculate total storage used by all OneDrive for Business accounts
$TotalODFBGBUsed = [Math]::Round(($ODFBSites.'Storage Used (Byte)' | Measure-Object -Sum).Sum / 1GB, 2)

# Initialize a list to store report data
$Report = [System.Collections.Generic.List[Object]]::new()

# Populate the report with detailed information for each OneDrive site
foreach ($Site in $ODFBSites) {
    $UserData = $UserHash[$Site.'Owner Principal name']
    $ReportLine = [PSCustomObject]@{
        Owner             = $Site.'Owner display name'
        UserPrincipalName = $Site.'Owner Principal name'
        SiteId            = $Site.'Site Id'
        IsDeleted         = $Site.'Is Deleted'
        LastActivityDate  = $Site.'Last Activity Date'
        FileCount         = [int]$Site.'File Count'
        ActiveFileCount   = [int]$Site.'Active File Count'
        QuotaGB           = [Math]::Round($Site.'Storage Allocated (Byte)' / 1GB, 2)
        UsedGB            = [Math]::Round($Site.'Storage Used (Byte)' / 1GB, 2)
        PercentUsed       = [Math]::Round($Site.'Storage Used (Byte)' / $Site.'Storage Allocated (Byte)' * 100, 2)
        City              = $UserData.city
        Country           = $UserData.country
        Department        = $UserData.department
        JobTitle          = $UserData.jobTitle
    }
    $Report.Add($ReportLine)
}

# Export the report to a CSV file and display the data in a grid view
$Report | Sort-Object UsedGB -Descending | Export-CSV -NoTypeInformation -Encoding utf8 $CSVOutputFile
$Report | Sort-Object UsedGB -Descending | Out-GridView -Title OneDriveUsageReport

Write-Host ("Current OneDrive for Business storage consumption is {0} GB. Report saved to {1}" -f $TotalODFBGBUsed, $CSVOutputFile) -ForegroundColor Cyan

# Reset tenant report data concealment setting if it was modified earlier
if ($ConcealedFlag -eq $true) {
    Write-Host "Re-enabling data concealment in tenant reports..." -ForegroundColor Cyan
    $Parameters = @{ displayConcealedNames = $true }
    Update-MgAdminReportSetting -BodyParameter $Parameters
}

# Clean up the temporary export file
if (Test-Path $TempExportFile) {
    Remove-Item $TempExportFile
    Write-Host "Temporary export file removed." -ForegroundColor Cyan
}
  • 第24/25行:編輯CSV文件路徑

步驟3。運行Got-onedriversizereport PowerShell腳本

在下面運行命令以運行Get-onedrivesizereport.ps1Powershell腳本。

c:scripts.Get-OneDriveSizeReport.ps1

下面的輸出出現。

Unhiding concealed report data to retrieve full user information...
Fetching user account details from Microsoft Graph...
Retrieving OneDrive for Business site usage details...
Current OneDrive for Business storage consumption is 124,19 GB. Report saved to C:tempOneDriveSizeReport.csv
Re-enabling data concealment in tenant reports...
Temporary export file removed.

報告輸出將發送到單獨的窗口中的交互式表(Out-GridView)。

步驟4。檢查OneDrive用法報告CSV文件

Got-onedrivesizereport.ps1 powershell腳本將所有Microsoft 365用戶登錄到CSV文件。

查找文件Onedrivesizereport.csv在路徑中C:溫度

使用您喜歡的應用程序打開CSV文件。在我們的示例中,這是Microsoft Excel。

就是這樣!

筆記:從2025年1月開始,微軟將向組織收取無許可的OneDrive帳戶存儲。知道哪些帳戶未經許可的絕佳方法是獲取無許可的OneDrive用戶帳戶報告

結論

您學習瞭如何在Microsoft 365中導出OnEdrive用法報告。如果要立即檢查用戶的OneDrive尺寸數據,請查找Microsoft 365 Admin Center中的用戶。要獲取更多詳細信息的報告,請使用Microsoft 365 Admin Center中的報告部分或使用PowerShell。缺點是您需要等待48小時才能獲得數據。

您喜歡這篇文章嗎?您可能還喜歡帶有PowerShell腳本的Microsoft 365安全建議。不要忘記關注我們並分享這篇文章。