Office 365: How to get the storage being used in ODFB by using PowerShell!

This time I’m sharing a new script that allows to get the storage being used in OneDrive For Business (ODFB) for every user in a Office 365 tenant. You can download the script from the following link: How to get all the space used in ODFB for each user in an Office 365 tenant

############################################################################################################################################

# Script that allows to get the storage space being used in ODFB for everyuser in an Office 365 tenant

# Required Parameters:

#  -> $sUserName: User Name to connect to the SharePoint Admin Center.

#  -> $sMessage: Message to show in the user credentials prompt.

#  -> $sSPOAdminCenterUrl: SharePoint Admin Center Url

#  -> $sSPOODFBHostUrl: SharePoint ODFB Host URL

############################################################################################################################################

 

 

 

$host.Runspace.ThreadOptions = "ReuseThread"

 

#Definition of the function that gets the storage space being used in ODFB for everyuser in an Office 365 tenant

function Get-OneDriveFBUsedSpace

{

    param ($sUserName,$sMessage,$sSPOAdminCenterUrl,$sSPOODFBHostUrl)

    try

    {    

        Write-Host "----------------------------------------------------------------------------------"  -foregroundcolor Green

        Write-Host "Getting all storage space being used by end users in ODFB in an Office 365 tenant" -foregroundcolor Green

        Write-Host "----------------------------------------------------------------------------------"  -foregroundcolor Green

        $msolCred = Get-Credential -UserName $sUserName -Message $sMessage

        Connect-MsolService -Credential $msolCred

        Connect-SPOService -Url $sSPOAdminCenterUrl -Credential $msolCred 

        $spoUsers=Get-MsolUser        

        ForEach ($spoUser in $spoUsers){

            ForEach ($O365Plan in $spoUser.Licenses.ServiceStatus){

                if (($O365Plan.servicePlan.servicename -like 'SharepointEnterprise') -and $O365Plan.ProvisioningStatus -eq 'Success')

                {                           

                    try{                        

                        $spoODFBUrl=$sSPOODFBHostUrl + $spoUser.UserPrincipalName.Replace(".","_").Replace("@","_")

                        $spoODFB=Get-SPOSite -Identity $spoODFBUrl

                        $spoODFBUsedSpace=$spoODFB.StorageUsageCurrent

                        Write-Host "ODFB Site: " $spoUser.UserPrincipalName " - Storage (MB): " $spoODFBUsedSpace " MB"     

               

                    }catch{

                        [string]::Format("{0},N/A",$spoUser.UserPrincipalName)

                    }

                }

            }

        }

    }

    catch [System.Exception]

    {

        write-host -f red $_.Exception.ToString()   

    }    

}

 

#Connection to Office 365

$sUserName="<Office365User>@<Office365Domain>"

$sMessage="Introduce your SPO Credentials"

$sSPOAdminCenterUrl="https://<Office365Domain>-admin.sharepoint.com/"

$sSPOODFBHostUrl="https://<Office365Domain>-my.sharepoint.com/personal/"

 

Get-OneDriveFBUsedSpace -sUserName $sUserName -sMessage $sMessage -sSPOAdminCenterUrl $sSPOAdminCenterUrl -sSPOODFBHostUrl $sSPOODFBHostUrl

Bellow you can find the output generated once you execute the script in PowerShell ISE:

image

Un pensamiento en “Office 365: How to get the storage being used in ODFB by using PowerShell!

  1. Pingback: SharePoint 2013 & Office 365: Resumen de posts (LXIX)! | Pasión por la tecnología...

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s