Skip to content

Instantly share code, notes, and snippets.

@jdmills-edu
Last active September 21, 2017 14:12
Show Gist options
  • Save jdmills-edu/7fb71101fff222498ed006bb5d411a61 to your computer and use it in GitHub Desktop.
Save jdmills-edu/7fb71101fff222498ed006bb5d411a61 to your computer and use it in GitHub Desktop.
A PowerShell script that gathers storage space utilization for all users in your Dropbox Business tenant, grouped by Active Directory Title. This example is written for .edu's that use the Student/Staff/Faculty title schema, but you could modify the script to use any other title schema you prefer, or simply use it to collect the storage utilizat…
#Specify your Dropbox AD Group (the one you use with the AD Connector)
$DropboxADGroupName = "YourDropboxUsersADGroup"
#API token from https://www.dropbox.com/developers/apps
$token = 'Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
#Get Dropbox Users via the DfB API
$allDfBAPIUsers = &DropboxAPI-ListMembers.ps1
$allDfBAPIUsers = $allDfBAPIUsers | where team_member_id
$dfBAPIUsersFormatted = $allDfBAPIUsers | Select team_member_id, @{Name="Username";Expression={$_.email.split("@")[0]}}, email
#Get all AD User objects for members of your Dropbox AD Connector group, including the title.
Write-Host "Getting Dropbox AD Group user objects..."
$DropboxADUsers = Get-ADGroupMember -Identity $DropboxADGroupName -Recursive | Get-ADUser -Properties "Title"
$matchedUsers = @()
$i = 0
$DropboxADUsers | ForEach-Object {
Write-Progress -Activity "Matching AD accounts to DfB users..." -Status $_.SamAccountName -PercentComplete (($i/$DropboxADUsers.Count)*100)
$matchedUser = [PSCustomObject]@{
Username = $_.SamAccountName
Title = $_.Title
DropboxID = ($dfBAPIUsersFormatted | where Username -eq $_.SamAccountName | Select team_member_id).team_member_id
}
$matchedUsers += $matchedUser
$i++
}
Write-Progress -Activity "Matching AD accounts to DfB users..." -Completed
$matchedStudents =$matchedUsers | where Title -eq "Student"
$matchedStaff = $matchedUsers | where Title -eq "Staff"
$matchedFaculty = $matchedUsers | where Title -eq "Faculty"
$json = "null"
$body = ([System.Text.Encoding]::UTF8.GetBytes($json))
#Iterate through all users grouped by title. Use the Dropbox-API-Select-User header to impersonate the user, allowing access to User API endpoints.
$i = 0
$matchedStudents | ForEach-Object {
Write-Progress -Activity "Getting each user's storage utilization..." -Status $_.Username -PercentComplete (($i/$matchedUsers.Count)*100)
$headers = @{ Authorization = $token; 'Dropbox-API-Select-User' = $_.DropboxID }
$_ | Add-Member -Name StorageUtilization -MemberType NoteProperty -Force `
-Value (((Invoke-RestMethod -Uri https://api.dropboxapi.com/2/users/get_space_usage -Method Post -Headers $headers -Body $body -ContentType "application/json; charset=utf-8") | Select Used).Used)
$_
$i++
}
Write-Progress -Activity "Getting each user's storage utilization..." -Completed
$i = 0
$matchedFaculty | ForEach-Object {
Write-Progress -Activity "Getting each user's storage utilization..." -Status $_.Username -PercentComplete (($i/$matchedUsers.Count)*100)
$headers = @{ Authorization = $token; 'Dropbox-API-Select-User' = $_.DropboxID }
$_ | Add-Member -Name StorageUtilization -MemberType NoteProperty -Force `
-Value (((Invoke-RestMethod -Uri https://api.dropboxapi.com/2/users/get_space_usage -Method Post -Headers $headers -Body $body -ContentType "application/json; charset=utf-8") | Select Used).Used)
$_
$i++
}
Write-Progress -Activity "Getting each user's storage utilization..." -Completed
$i = 0
$matchedStaff | ForEach-Object {
Write-Progress -Activity "Getting each user's storage utilization..." -Status $_.Username -PercentComplete (($i/$matchedUsers.Count)*100)
$headers = @{ Authorization = $token; 'Dropbox-API-Select-User' = $_.DropboxID }
$_ | Add-Member -Name StorageUtilization -MemberType NoteProperty -Force `
-Value (((Invoke-RestMethod -Uri https://api.dropboxapi.com/2/users/get_space_usage -Method Post -Headers $headers -Body $body -ContentType "application/json; charset=utf-8") | Select Used).Used)
$_
$i++
}
Write-Progress -Activity "Getting each user's storage utilization..." -Completed
@jdmills-edu
Copy link
Author

Here's DropboxAPI-ListMembers.ps1 referenced in line 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment