Change specific users OneDrive For Business quotas using PowerShell
It may be useful to allocate specific users with specific OneDrive for Business storage quotas. But we may be faced with some challenges trying to achieve that…
In this blog post, we’ll use a
.csv file containing the users we wish to change the quota for, as well as adding some error handling to our script to manage the outcomes 🧐
And to top it off, we’ll export the “users not found” so you’re not in the dark when closing your PowerShell console!
What could the errors be?
We’re interacting with 2 different things here:
- Usernames (i.e.: User Principal Names)
- OneDrive for Business (not auto-magically provisioned!)
So thinking about our script, maybe we have a user who’s not in our tenant (typo?) or maybe his/her OneDrive is not provisioned? If OneDrive is not provisioned, it means either the user doesn’t have a license for SharePoint Online, or he/her simply didn’t access it at all.
We’ll have 2 parts in this script:
- Change the quota for specific users
- Handles errors differently depending on the type (more details below) Let’s get started.
Let’s create a simple CSV file with the (new) quotas & warning for each user. Our quotas need to be in BYTES.
Cmdlets & Variables
We’ll use 3 variables and 1 cmdlet here.
$usernamesto import our CSV file containing the users
$resultsto store the users having problems
$logFileto export the users having problems
- Set-PnPUserOneDriveQuotato change the quotas for each user
Now let’s put everything together 🙂
What are we doing here?
- We use a
Try/Catchto handle the errors
- We loop through each user in our CSV file and (try to) set the new values
- We catch 2 possible errors:
- “Unknown error” when OneDrive is not provisioned
- “Something else” when the user doesn’t exist in our tenant
- We export the results to a file
Here is what it would look like 👇
Running the script:
- BiancaP doesn’t have a ODFB provisioned (but she’s part of our the tenant) –-> Unknown error
- user123 is not part of our tenant (or maybe you have a typo!) –-> User not found in the domain
Users with problems are also exported:
There we go, thanks for reading!