Calculate the Size of Filebase Buckets using PowerShell
Learn how to calculate the size of Filebase Buckets using PowerShell.
What is PowerShell?
PowerShell is a task automation and configuration management program created by Microsoft that consists of a command-line shell interface and a built-in scripting language. PowerShell is available for Windows, macOS, and Linux operating systems.
Read below to learn how to calculate the size of Filebase Buckets using PowerShell.
Filebase would like to thank Trevor Sullivan from CBTNuggets for the original version and publication of this tutorial guide.
1. Open your PowerShell command line.
First, we need to install the Amazon S3 module for use with Filebase. Install this module with the command:
Install-Module -Name AWS.Tools.S3 -Scope CurrentUser -Force
2. Next, we need to configure our Filebase credentials.
To do this, use the following command:
Set-AWSCredential -StoreAs Filebase -AccessKey ACCESS_KEY -SecretKey SECRET_KEY
Replace the ACCESS_KEY with your Filebase Access Key, and the SECRET_KEY with your Filebase Secret Key.
3. Next, to calculate the size of a Filebase bucket, we’ll use the Get-S3Object command.
This command will list the objects stored in your Filebase bucket, then we’ll store it as an environment variable in memory for us to reference after:
$ObjectList = Get-S3Object -BucketName FILEBASE_BUCKET_NAME -EndpointUrl https://s3.filebase.com -Region us-east-1 -ProfileName filebase
Replace FILEBASE_BUCKET_NAME
with your Filebase bucket name.
4. Then, we can reference the variable $ObjectList, and pipe the output into the Select-Object command that includes a filter for Size only, since this is the only property we are concerned about.
Then, we can pipe this into another command called Measure-Object which can create a sum of the numeric values we got from the Select-Object -Property Size command. Lastly, we’ll save this entire output as the $Sum variable:
$Sum = $ObjectList | Select-Object -ExpandProperty Size | Measure-Object -Sum
5. Since this output includes different properties, not only the Sum property, we’ll extract only the Sum property with the command:
$Sum.Sum
This value might be hard to read if you have a large amount of data stored in your bucket, so we can refine this output by Gigabytes with the following filter:
$Sum.Sum/1GB
6. This workflow is great for calculating individual bucket size, but what about calculating the size of all buckets on your Filebase account?
Here’s a bit of code that can accomplish just that:
Last updated