/ Powershell

Powershell snippet/function for extending OneDrive for Business Quota to 5 TB

Our Office 365 plans recently received an increased OneDrive for Business quota (from 1 TB to 5 TB) and of course some users want/need this change right away. So let's start.

First we need to connect to SPO:

$cred = Get-Credential
Connect-SPOService https://<tenant>-admin.sharepoint.com -Credential $cred
```<br>
Secondly I've made a function that will:

* Get the AD-user of `$UserName`
* Construct the url (identity) needed from the `UserPrincipalName`
* Check if the user already have the correct quota, otherwise fix it.

```powershell
function fix-OneDriveQuotaIfNeeded ($Username)
{
    Write-Host "Fixing $Username"
    $userObj = Get-ADUser $Username
    $identity = "https://<tenant>-my.sharepoint.com/personal/{0}" -f $userObj.UserPrincipalName.replace("@","_").replace(".","_")
    Write-host " -> Old Quota: "  -NoNewline -ForegroundColor Gray
    $quota = (Get-SPOSite $Identity).StorageQuota
    if ($quota -lt $NewQuota)
    {       
        Write-host $quota -ForegroundColor Yellow
        Write-Host " -> New quota: " -NoNewline -ForegroundColor Gray
        Set-SPOSite -Identity $Identity -StorageQuota 5242880
        Write-host "5242880" -ForegroundColor Green
    }
    else
    {
        Write-host "$quota (all good)" -ForegroundColor Green
    }
}
``` <br>
Let's say we want to fix one user, then all we have to do is: `fix-OneDriveQuotaIfNeeded johndoe01`. If we want to fix all users: `Get-ADUser -searchbase OU=Users,DC=dc,Dc=com | % {fix-OneDriveQuotaIfNeeded $_.Name}`.

Don't forget to disconnect the session when you are done:
```powershell
Disconnect-SPOService
```<br>
Enjoy ;)
Andreas Selevik

Andreas Selevik

Solution Architect specialized in Windows & Azure Architecture, Office 365, PowerShell, Identity management and automation. Manchester United fanatic, father, husband and a very good winner...

Read More