Back to blog

Who is not using OneDrive for Business within your Office 365 environment?

Nov 2, 2015 by Ian Byrne

So you’ve brought your business kicking and screaming into the digital age by moving to the cloud with Microsoft Office 365. There are lots of great tools that come with many of the Office 365 subscriptions, one of them being OneDrive for Business. This allows your users to create, sync and share documents and files from anywhere in the world – but how many of these users have actually begun to adopt it?

This PowerShell script will connect to the SharePoint API, where your OneDrive for Business data is stored, and export a list of users who have not made a change to their Documents library in the past two weeks. Your organization may use additional libraries, so be sure to adjust the script to include these too.

You may need to first download and install the SharePoint Server 2013 Client Components SDK. Be sure to also populate the $company variable based on your [$company] tenant domain, as well as the $username and $pass variables with your admin credentials.

You can download this script at the TechNet Script Center.

$company = "companyname"
$username = ""
$pass = "pass" | ConvertTo-SecureString -asPlainText -Force
$exportPath = "C:\cogmotive\inactiveUsers.csv"
$limit = (Get-Date).AddDays(-14) # The number of days of inactivity to report on
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") # This allows us to increase the default JSON Length
$JsonSerial = New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer
$JsonSerial.MaxJsonLength = [int]::MaxValue
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$pass)
Function Connect-API($url)
$request = [System.Net.WebRequest]::Create($Url)
$request.Credentials = $credentials
$request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")
$request.Accept = "application/json;odata=verbose"
$request.Method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get
$response = $request.GetResponse()
if ($response)
$requestStream = $response.GetResponseStream()
$readStream = New-Object System.IO.StreamReader $requestStream
$results = $JsonSerial.DeserializeObject($data)
RETURN $results.d
$url = "https://" + $company + "`$filter=PrincipalType eq 1&`$select=loginname"
$users = Connect-API $url
$inactiveUsers = @()
foreach ($user in $users.results)
$LoginNameString = $user.LoginName.Split("|") # The LoginName string contains some metadata, separated with a pipe |
if ($LoginNameString[1] -eq "membership") # Users with this "membership" flag are the only ones we are interested in
$loginname = ($LoginNameString[2].replace('.','_')).replace('@','_') # Convert the username from to user_company_com to be re-fed to the API
$userListsURL = "https://" + $company + "" + $loginname + "/_api/web/lists/" + "?`$select=Hidden,Title,LastItemModifiedDate,LastItemDeletedDate"
$userLists = Connect-API $userListsURL
if ($userLists)
foreach ($userList in $userLists.results)
# Only worry about the "Documents" library, if it meets the date limits. Be sure to add any additional libraries that your organisation uses
if (($userList.Title -eq "Documents") -and ((get-date $userList.LastItemModifiedDate) -lt $limit) -and ((get-date $userList.LastItemDeletedDate) -lt $limit))
write-host $LoginNameString[2]
$inactiveUsers += ,$LoginNameString[2]
$inactiveUsers = $inactiveUsers | Select-Object @{Name='User';Expression={$_}}
$inactiveUsers | Export-Csv $exportPath -NoTypeInformation

As simple as that – With this list of “inactive” users, you can gain a better understanding of OneDrive for Business usage within your organization. We provide this data with a lot more in-depth information in our Inactive OneDrive Users report as part of our SharePoint Online Reports tool.

Inactive OneDrive Chart
Learn more about our Office 365 reporting software and gain immediate insights into your Office 365 environment!