Gettting the folder id
Hi Team,
Is there any code snippet available or any possible way we can get the folder size if we provide the folder id ?
Thanks ,
Maneesh
-
Hi Maneesh,
I don't use the regular APIs directly that much but do leverage the Box CLI within PowerShell scripts. You can get the folder size using the standard using the regular Get Folder Informtion: https://box.dev/reference/get-folders-id/
The following PowerShell snippet is what I use - it is probably not the most elegant or efficient but works. My input file is in the following format but for this only needs the FolderID - I just happen to use the csv for other purposes as well.
Input File:
id,login,folderid
0000,xxxx,9999
Sample Box CLI PowerShell script:
if($args.count -eq 2)
{
$inputfile=$args[0]
$outputfile=$args[1]
}else
{
Write-Output "Usage: ps .\box-get-users-share-size-report.ps1 inputfile outputfile"
exit
}
$box_adminid = "xxxxx" # Box Support ID with appropriate permissions
$csv = Import-Csv $inputfile -delimiter ","$myarray = @()
$count = 0
$totalUsers = $csv.Count
Foreach ($csv in $csv){
$json = box folders:get $csv.folderid --as-user $box_adminid
$parsed = $json | ConvertFrom-Json$myarray += [PSCustomObject] @{
login = $csv.login
folder = $parsed.name
size = ($parsed.size/1000000000)
}
$count = $count + 1Write-Progress -activity "Compiling Box Folder Stats . . ." -status "Scanned: $count of $totalUsers" -PercentComplete (($count / $totalUsers) * 100)
}$myarray | ConvertTo-Csv -NoTypeInformation | Set-Content $outputfile
Write-Output ""
Write-Output ""
Write-Output "Processing complete: "$count" User folders found."
Write-Output ""Hope that helps.
Jeff
Please sign in to leave a comment.
Comments
1 comment