{"id":164,"date":"2014-08-06T08:14:03","date_gmt":"2014-08-06T08:14:03","guid":{"rendered":"http:\/\/blogs.kent.ac.uk\/unseenit\/?p=164"},"modified":"2014-08-06T08:14:03","modified_gmt":"2014-08-06T08:14:03","slug":"grabbing-mailbox-usage-statistics-from-office365-regularly","status":"publish","type":"post","link":"https:\/\/blogs.kent.ac.uk\/unseenit\/grabbing-mailbox-usage-statistics-from-office365-regularly\/","title":{"rendered":"Grabbing mailbox usage statistics from Office365 regularly"},"content":{"rendered":"<p>Office365 now exposes a number of reports which will hopefully be useful for measuring usage and engagement of mailbox users.<\/p>\n<p>One such report is the &#8220;Active and inactive mailboxes&#8221; report exposed within the Admin Portal:<\/p>\n<p><a href=\"http:\/\/blogs.kent.ac.uk\/unseenit\/files\/2014\/08\/https___portal_office_com_default_aspx_AllReportsRootV2.png\"><img loading=\"lazy\" class=\"alignnone size-medium wp-image-165\" src=\"http:\/\/blogs.kent.ac.uk\/unseenit\/files\/2014\/08\/https___portal_office_com_default_aspx_AllReportsRootV2-300x177.png\" alt=\"https___portal_office_com_default_aspx_AllReportsRootV2\" width=\"300\" height=\"177\" srcset=\"https:\/\/blogs.kent.ac.uk\/unseenit\/files\/2014\/08\/https___portal_office_com_default_aspx_AllReportsRootV2-300x177.png 300w, https:\/\/blogs.kent.ac.uk\/unseenit\/files\/2014\/08\/https___portal_office_com_default_aspx_AllReportsRootV2-1024x604.png 1024w, https:\/\/blogs.kent.ac.uk\/unseenit\/files\/2014\/08\/https___portal_office_com_default_aspx_AllReportsRootV2-500x295.png 500w, https:\/\/blogs.kent.ac.uk\/unseenit\/files\/2014\/08\/https___portal_office_com_default_aspx_AllReportsRootV2.png 1287w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>In order to retrieve these data over time programatically, I&#8217;ve written a Powershell script to grab the data from the Get-MailboxActivityReport cmdlet and store it in a date stamped CSV. This requires a password to be stored (securely) but can then be invoked manually or from Task Scheduler automatically \ud83d\ude42<\/p>\n<p>&nbsp;<\/p>\n<h1>Script<\/h1>\n<pre>Param(\r\n[Parameter(Mandatory=$True)] [string] $User,\r\n[Parameter(Mandatory=$True)] [string] $CredentialFile,\r\n[Parameter(Mandatory=$True)] [string] $CSVBase\r\n)\r\n\r\n$now = get-date -UFormat \"%Y-%m-%dT%H%M%S\"\r\n\r\nWrite-Verbose \"Setting up credential object for $user using $credentialfile\"\r\n$password = get-content $CredentialFile -ErrorAction Stop | ConvertTo-SecureString -ErrorAction stop\r\n$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $password\r\n\r\nWrite-Verbose \"Setting up PowerShell\"\r\nImport-Module MSOnline -ErrorAction stop\r\n\r\nWrite-Verbose \"Connecting to MSFT\"\r\nConnect-MsolService -Credential $cred -ErrorAction stop\r\n$global:PSSession = New-PSSession -ErrorAction stop -ConfigurationName Microsoft.Exchange `\r\n    -ConnectionUri https:\/\/ps.outlook.com\/powershell `\r\n    -Credential $cred `\r\n    -Authentication Basic `\r\n    -AllowRedirection\r\n\r\nImport-PSSession $PSSession -CommandName Get-MailboxActivityReport -ErrorAction stop\r\n\r\nWrite-Verbose \"Requesting data\"\r\n$data = Get-MailboxActivityReport\r\n\r\nWrite-Verbose \"Exporting data\"\r\n$data | export-csv -LiteralPath $CSVBase\"-\"$now\".csv\"\r\n<\/pre>\n<h2>Storing the password securely<\/h2>\n<p>Invoke the following as the user you&#8217;re going to run this as:<\/p>\n<pre>\r\nread-host -assecurestring | convertfrom-securestring | out-file cred.txt\r\n<\/pre>\n<h1>Invoking the script<\/h1>\n<pre>\r\ngetmailboxstats.ps1 -user admin@example.com -CredentialFile .\\cred.txt -CSVBase mailboxstats\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Office365 now exposes a number of reports which will hopefully be useful for measuring usage and engagement of mailbox users. One such report is the &hellip; <a href=\"https:\/\/blogs.kent.ac.uk\/unseenit\/grabbing-mailbox-usage-statistics-from-office365-regularly\/\">Read&nbsp;more<\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[28933],"tags":[28920,28935],"_links":{"self":[{"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/posts\/164"}],"collection":[{"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/comments?post=164"}],"version-history":[{"count":3,"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/posts\/164\/revisions"}],"predecessor-version":[{"id":168,"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/posts\/164\/revisions\/168"}],"wp:attachment":[{"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/media?parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/categories?post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/unseenit\/wp-json\/wp\/v2\/tags?post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}