0
Dropbox管理コンソールで利用可能なストレージ情報や共有フォルダ数などのDropboxメトリックにアクセスしたいと思います。 Dropbox APIはかなりの量の情報に豊富なアクセスを提供しているので、Powershellを介してこの情報にどのようにアクセスできますか?Powershellを介してDropboxメトリックにアクセス
Dropbox管理コンソールで利用可能なストレージ情報や共有フォルダ数などのDropboxメトリックにアクセスしたいと思います。 Dropbox APIはかなりの量の情報に豊富なアクセスを提供しているので、Powershellを介してこの情報にどのようにアクセスできますか?Powershellを介してDropboxメトリックにアクセス
このAPIは、メトリクスについて何日もの情報を提供します。以下の例では1.0 APIを使用していますが、これはまもなくバージョン2.0に置き換えられています。 APIのドキュメントについては、Dropbox.com/developerを参照してください。
この例では、最新のストレージおよび共有フォルダのメトリックを生成しています。
サンプル出力:
2016年4月27日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")