Chat with us, powered by LiveChat

Blog

Back

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

2 Nov 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 organisation 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].onmicrosoft.com 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 = "user@company.com"
$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
$data=$readStream.ReadToEnd()
$results = $JsonSerial.DeserializeObject($data)
RETURN $results.d
}
}
$url = "https://" + $company + "-my.sharepoint.com/_api/web/siteusers?`$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 user@company.com to user_company_com to be re-fed to the API
$userListsURL = "https://" + $company + "-my.sharepoint.com/personal/" + $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 organisation. 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
Sign up today for a free 14-day trial and gain immediate insights into your Office 365 environment!