通过Powershell访问Dropbox指标

时间:2016-04-28 16:11:52

标签: powershell dropbox dropbox-api

我想访问类似于Dropbox管理控制台上提供的Dropbox指标,例如存储信息和共享文件夹计数。 Dropbox API提供了对大量信息的丰富访问,因此我如何通过Powershell获取此信息?

1 个答案:

答案 0 :(得分:0)

API将提供有关指标的多日信息。下面的示例使用1.0 API,很快就会被2.0版取代。有关API的文档,请访问Dropbox.com/developer

此示例生成最新的存储和共享文件夹指标。

示例输出:

04/27/2016 00:00:00,6220390,2163

# Prompt or hard-code  for Team Member Management permission 
# the Token is obtained from Dropbox website - the Admin Console
#$token = Read-Host -Prompt "Enter your Dropbox Business API App token (Team Member Management permission): " 
$token = "Bearer KXasdflkjasfoivXnasdliefdslksafToivU932432489432" 

$object = New-Object psobject 

# Make API call 
$teamstats = Invoke-RestMethod -Uri https://api.dropbox.com/1/team/reports/get_storage -Body (ConvertTo-Json $object) -ContentType application/json -Headers @{ 
            Authorization = $token } -Method Post 

# API returns 1 startdate only, which is the day before the data actually begins 
$startdate = [datetime]$teamstats.start_date

#API returns in an array various elements such as storage consumed & number of shared folders
#below I convert them to an array with a simpler name
$StorageArray = $teamstats.total_usage
$ShareArray = $teamstats.shared_folders

# of entries in the array
$MaxCount = $storagearray.length

# I am only interested in the last entry (most current)
$LastEntry = $MaxCount - 1

#adjust the date so it reflects the right time period
$ts = New-TimeSpan -Days $lastentry
$startdate = $startdate + $ts

#grab the last entry for storage and shares
$storage = $StorageArray[$LastEntry]
$Shares = $ShareArray[$LastEntry]

#I load this data into other software, which cannot deal with storage in Bytes
#when the number is so large (terabytes)
#so I convert it to megabytes
[long]$intNum = $Storage -as [long]
$intnum = $intnum / (1024 * 1024) # convert to mb

"$startdate,$intnum,$Shares"

Write-Host "Press any key to continue ..."

$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")