p$: OneDrive Size Script

By | July 15, 2019

Source: Missing (if this is your script/work, please let me know so I can give proper credit)

#Replace the following three variables with your information
#Note: The $tenant variable is just the first part in front of ______.onmicrosoft.com, 
#Note: The $SharePointSKU variable can vary depending on your license type. For example, it could be SharepointEnterprise, SharepointEnterprise_GOV, SharepointStandard_EDU
$SharePointSKU = 'SharepointEnterprise'
$tennnatadmin = "https://$tennant-admin.sharepoint.com"

#Enter an O365 Global Admin username and password
$o365cred = Get-Credential -UserName $username -Message "Please Enter Password" 

Connect-MsolService -Credential $o365cred 
Connect-SPOService -Url $tennnatadmin -Credential $o365cred

$myarray = @()
$resultshash = @{}

$users=get-msoluser -All
foreach ($user in $users){
    Foreach ($Plan in $User.Licenses.ServiceStatus){
        if (($Plan.servicePlan.servicename -like $SharePointSKU) -and $Plan.ProvisioningStatus -eq 'Success')
                $url=$onedriveurl + $user.UserPrincipalName.Replace(".","_").Replace("@","_")
                $OneDrive=Get-SPOSite $url                                    
                        $myarray += New-Object psobject -Property @{DisplayName=$user.DisplayName.ToString();UPN=$user.UserPrincipalName.ToString();Country=$user.Country;LastModifiedDate=$OneDrive.LastContentModifiedDate; Size=$onedrive.StorageUsageCurrent} -ErrorAction SilentlyContinue             
                  $myarray += New-Object psobject -Property @{DisplayName=$user.DisplayName.ToString();UPN=$user.UserPrincipalName.ToString();Country=$user.Country;LastModifiedDate=$OneDrive.LastContentModifiedDate;Size="0"} -ErrorAction SilentlyContinue             
$currentdate = Get-Date -Format "MM-dd-yyyy"
$myarray | Select DisplayName,UPN,Country,LastModifiedDate,Size|  Export-Csv c:\Temp\OneDriveUserStorage_$currentdate.csv -NoTypeInformation
# Note: when you open c:\Temp\OneDriveUserStorage_$currentdate.csv then keep in mind this information: 
# A size of zero means OneDrive has not been provisioned
# A size of 1 means OneDrive has been provisioned but not used
# A size of larger than zero is the size of there OneDrive storage.

Be kind, be safe and have an outstanding day!

-Bill Beehner