Using MicrosoftGraph API in C# (or VB) to access mailbox usage information

Brass Contributor

Hi

 

Currently I use a powershell script such as below to get sizes of mailboxes in my organization

 

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

$ExportFile = ([Environment]::GetFolderPath("Desktop")+"\Mailboxes.csv")

Get-Mailbox | Get-MailboxStatistics | Select DisplayName, TotalItemSize, ItemCount | Sort ItemCount -Descending | Export-CSV $ExportFile -NoTypeInformation

Remove-PSSession $Session

 

But I want to start programming using the Microsoft Graph API so I can write an app to pull out various bits of information - the first of which is the mailbox 

 

Using the example here = https://github.com/microsoftgraph/console-csharp-snippets-sample I can connect to my Office 365 / Exchange Online mailbox and pull out information

 

But I can't see where I can get mailbox statistics such as mailbox size like I can get using my powershell

 

Perhaps someone can point me in the right direction? or comment if better way of doing it?

 

Basically want to regularly check sizes and send alert when particular mailboxes get too large (usually ones used by a service account rather than a user)

 

Many thanks

3 Replies

I see that above you're using Exchange Powershell, then why cant you automate it with .Net (using C#.Net). Please refer: https://blogs.msdn.microsoft.com/wushuai/2016/09/18/access-exchange-online-by-powershell-in-c/

 

Hope this helps.

That is what I have done in the end - used PowerShell from VB.NET using System.Management.Automation from NuGet and it is working fine.

 

Originally I thought Graph API was the way forward and a better way to do things, but after lack of responses on all forums, lack of documentation etc I decided to stick with what I know

 

Thanks