Loading...

OneDrive and PowerShell: Get size and size on disk

Reply A+ A-


In this post I will show you a quick script allowing you to display OneDrive size, and onedrive size on disk.


Context

You want to get inforomation about size, meaning size of your files on OneDrive:

- Full size of your files

- Size on your disk


When you do a rigth-click on your OneDrive folder, you can get this information:


The size on disk part means the size that a file takes on your local drive.

When you go inside your OneDrive folder there are some different behaviors:

- File with a blue cloud icon: located on the cloud and not on your drive

- File with a green check: located on OneDrive but downloaded once


For instance let's do a test:

1. Add a 1GB file on OneDrive.

2. Before the copy, the size on disk on OneDrive was 25,3 GB.


3. After the copy, the size on disk on OneDrive is still 25,3 GB.

4. If you check the file icon, it's the blue cloud meaning the file is on OneDrive but not on local drive.

5. Now let's double-click on the msi.

6. This will download the file locally, as below:

7. It means the file will have now size on your drive.

8. Once the download is complete, you will notice that the file icon is now a green check

9. Now the size on disk on OneDrive was 26,7 GB.



The solution

By default you can only get full size but not size actual size on disk.

To get both information, size and size on disk we will use bit of .NET class and function GetCompressedFileSizeW.

We will use Pinvoke.NET to access to some classes: 

- System

- System.Runtime.InteropServices

- System.ComponentModel

- System.IO


Get the script

Click on the below GitHub picture to get the script:


How it works 

1. Run the script Get_SizeOnDisk.ps1

2. Add parameter -OD_Path with path of your OneDrive

3. See below example:

$Path = 'C:\Users\damien.vanrobaeys\OneDrive - METSYS'

.\Get_SizeOnDisk.ps1 -OD_Path $Path

4. You will get the actual size of your onedrive files and the size on disk, as below:


Add parameter -Files_Size to get actual size and size on disk of each files.

This will also export size of each files on your OneDrive with below values:

- File name

- File path

- File size on OneDrive

- File size on Disk


See below an overview:



size n disk 463626918156492096

Enregistrer un commentaire

Accueil item

Award

Learn KQL in one month

Sponsors

You want to support me ?

Mes articles en français

Books in French


Stats