Skip to main content

Mailbox Size Gui - Exchange 2010 Remote Powershell version

One of the most popular scripts I've posted over the past few years has been the mailbox size gui for Exchange 2007 which evolved over a few different versions. While this is really only scratching the surface of the kind of cool things you can do with this information time and life hasn't really allowed me to make it better. But what i have managed to do is to port it to work with Exchange 2010 using remote powershell from a Windows 7 workstation.

A few challenges that needed to be solved to do this was first a front-end winform that allowed you to select the Exchange server you want to remote the powershell session to. Then some simple code to establish the remote PS Session which look like this

[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")

$form1 = new-object System.Windows.Forms.form
$form1.Text = "Exchange 2010 Remote PS Select"
$form1.size = new-object System.Drawing.Size(400,200)
$ServerName = ""
$conuri = ""
# Add Server DropLable
$snServerNamelableBox1 = new-object System.Windows.Forms.Label
$snServerNamelableBox1.Location = new-object System.Drawing.Size(10,20)
$snServerNamelableBox1.size = new-object System.Drawing.Size(120,20)
$snServerNamelableBox1.Text = "Remote ServerName"
$form1.Controls.Add($snServerNamelableBox1)

$exButton4 = new-object System.Windows.Forms.Button
$exButton4.Location = new-object System.Drawing.Size(10,80)
$exButton4.Size = new-object System.Drawing.Size(125,20)
$exButton4.Text = "Connect"
$exButton4.Add_Click({
$conuri = "http://" + $ServerName + "/PowerShell/"
$form1.close()
})
$form1.Controls.Add($exButton4)


# Add Server Drop Down
$snServerNameDrop1 = new-object System.Windows.Forms.ComboBox
$snServerNameDrop1.Location = new-object System.Drawing.Size(150,20)
$snServerNameDrop1.Size = new-object System.Drawing.Size(160,30)
$snServerNameDrop1.Add_SelectedValueChanged({$ServerName = $snServerNameDrop1.SelectedItem.ToString()})

$form1.Controls.Add($snServerNameDrop1)

$root = [ADSI]'LDAP://RootDSE'
$cfConfigRootpath = "LDAP://" + $root.ConfigurationNamingContext.tostring()
$configRoot = [ADSI]$cfConfigRootpath
$searcher = new-object System.DirectoryServices.DirectorySearcher($configRoot)
$searcher.Filter = '(objectCategory=msExchExchangeServer)'
[VOID]$searcher.PropertiesToLoad.Add("cn")
$searchres = $searcher.FindAll()
foreach ($res in $searchres){
$srvOjb = $res.Properties
$snServerNameDrop1.Items.Add($srvOjb.cn[0])
}

$form1.autoscroll = $true
$form1.Add_Shown({$form1.Activate()})
$form1.ShowDialog()

The next challenge was to do with the way the objects are sent and recieved between remote ps session which is explained in detail here. What this menas is that the Byte Quantified Size type isn't availble so what you recieve at the remote end is the string format version of the data structure which needs a simple parse to retrieve the byte information. With this

function CovertBitValue($String){
$numItempattern = '(?=\().*(?=bytes)'
$matchedItemsNumber = [regex]::matches($String, $numItempattern)
$Mb = [INT64]$matchedItemsNumber[0].Value.Replace("(","").Replace(",","")
return [math]::round($Mb/1048576,0)
}

This still needs a little more testing but seems to work okay I've put a download of the new script here.

Popular posts from this blog

Testing and Sending email via SMTP using Opportunistic TLS and oAuth in Office365 with PowerShell

As well as EWS and Remote PowerShell (RPS) other mail protocols POP3, IMAP and SMTP have had OAuth authentication enabled in Exchange Online (Official announcement here ). A while ago I created  this script that used Opportunistic TLS to perform a Telnet style test against a SMTP server using SMTP AUTH. Now that oAuth authentication has been enabled in office365 I've updated this script to be able to use oAuth instead of SMTP Auth to test against Office365. I've also included a function to actually send a Message. Token Acquisition  To Send a Mail using oAuth you first need to get an Access token from Azure AD there are plenty of ways of doing this in PowerShell. You could use a library like MSAL or ADAL (just google your favoured method) or use a library less approach which I've included with this script . Whatever way you do this you need to make sure that your application registration  https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-

How to access and restore deleted Items (Recoverable Items) in the Exchange Online Mailbox dumpster with the Microsoft Graph API and PowerShell

As the information on how to do this would cover multiple posts, I've bound this into a series of mini post docs in my GitHub Repo to try and make this subject a little easier to understand and hopefully navigate for most people.   The Binder index is  https://gscales.github.io/Graph-Powershell-101-Binder/   The topics covered are How you can access the Recoverable Items Folders (and get the size of these folders)  How you can access and search for items in the Deletions and Purges Folders and also how you can Export an item to an Eml from that folder How you can Restore a Deleted Item back to the folder it was deleted from (using the Last Active Parent FolderId) and the sample script is located  https://github.com/gscales/Powershell-Scripts/blob/master/Graph101/Dumpster.ps1

Using the MSAL (Microsoft Authentication Library) in EWS with Office365

Last July Microsoft announced here they would be disabling basic authentication in EWS on October 13 2020 which is now a little over a year away. Given the amount of time that has passed since the announcement any line of business applications or third party applications that you use that had been using Basic authentication should have been modified or upgraded to support using oAuth. If this isn't the case the time to take action is now. When you need to migrate a .NET app or script you have using EWS and basic Authentication you have two Authentication libraries you can choose from ADAL - Azure AD Authentication Library (uses the v1 Azure AD Endpoint) MSAL - Microsoft Authentication Library (uses the v2 Microsoft Identity Platform Endpoint) the most common library you will come across in use is the ADAL libraries because its been around the longest, has good support across a number of languages and allows complex authentications scenarios with support for SAML etc. The
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.