Skip to main content

EWS Outlook Quick Steps Powershell how to

Quickstep's in Outlook is a feature that was added in Outlook in 2010 to help automate repetitive tasks you do with Email in Outlook. In this Post I'm going to go through how you can manipulate the objects associated with Quick steps using EWS and PowerShell.

How Quick Steps are implemented in a Mailbox

The OuickSteps Folder is created by Outlook (eg no Outlook no folder) In the Mailbox's IPM Root as a hidden folder called Quick Steps (with a FolderClass of IPF.Configuration) and within this folder there are FAI (Folder Associated Items) which represent each of the QuickStep Items. On each of those there is a PidTagRoamingXmlStream property which contains a ByteArray that represents an XMLDocument for each of the QuickStep items for example they look something like


<?xml version="1.0"?>
<CombinedAction Ordinal="3200" Tooltip="" Icon="MoveToFolder" Name="Clutter" Version="147153">
 <ActionMoveToFolder>
  <Folder>80010....06F006D0000000000</Folder>
 </ActionMoveToFolder>
 <ActionMarkAsRead>
 </ActionMarkAsRead>
</CombinedAction>

Getting the QuickSteps Folder

To Get the QuickSteps folder (if it exists) you can use the PidTagAdditionalRenEntryIdsEx property on the IPM Root folder which will contain the HexEntryId of the QuickSteps folder in the RSF_PID_COMBINED_ACTIONS PersistBlockType value. Eg you can do this using the following code

function Get-QuickStepsFolder
{
 param(
  [Parameter(Position=0, Mandatory=$true)] [string]$MailboxName,
  [Parameter(Position=1, Mandatory=$true)] [PSCredential]$Credentials,
  [Parameter(Position=2, Mandatory=$false)] [Microsoft.Exchange.WebServices.Data.ExchangeService]$service 
 )
 Begin
 {
  if(!$service){
   $service = Connect-Exchange -MailboxName $MailboxName -Credential $Credentials
  }
  $PidTagAdditionalRenEntryIdsEx = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x36D9, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary)  
  $psPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)  
  $psPropset.Add($PidTagAdditionalRenEntryIdsEx)  
  $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)     
  $IPM_ROOT = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid,$psPropset)  
  $binVal = $null;  
  $AdditionalRenEntryIdsExCol = @{}  
  if($IPM_ROOT.TryGetProperty($PidTagAdditionalRenEntryIdsEx,[ref]$binVal)){  
      $hexVal = [System.BitConverter]::ToString($binVal).Replace("-","");  
      ##Parse Binary Value first word is Value type Second word is the Length of the Entry  
      $Sval = 0;  
      while(($Sval+8) -lt $hexVal.Length){  
          $PtypeVal = $hexVal.SubString($Sval,4)  
          $PtypeVal = $PtypeVal.SubString(2,2) + $PtypeVal.SubString(0,2)  
          $Sval +=12;  
          $PropLengthVal = $hexVal.SubString($Sval,4)  
          $PropLengthVal = $PropLengthVal.SubString(2,2) + $PropLengthVal.SubString(0,2)  
          $PropLength = [Convert]::ToInt64($PropLengthVal, 16)  
          $Sval +=4;  
          $ProdIdEntry = $hexVal.SubString($Sval,($PropLength*2))  
          $Sval += ($PropLength*2)  
          #$PtypeVal + " : " + $ProdIdEntry  
          $AdditionalRenEntryIdsExCol.Add($PtypeVal,$ProdIdEntry)   
      }     
  }
  $QuickStepsFolder = $null
  if($AdditionalRenEntryIdsExCol.ContainsKey("8007")){  
      $siId = ConvertFolderid -service $service -MailboxName $MailboxName -hexid $AdditionalRenEntryIdsExCol["8007"]  
      $QuickStepsFolderId = new-object Microsoft.Exchange.WebServices.Data.FolderId($siId.UniqueId.ToString())  
      $QuickStepsFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$QuickStepsFolderId) 
  }
  else{
   Write-Host ("QuickSteps folder not found")
   throw ("QuickSteps folder not found")
  }
  return $QuickStepsFolder
  

 }
 
}


Getting the Quick Steps Items

The Quick Step items are stored in the Folder Associated Items collection of the Quick Steps folder. To get these using EWS after you get the Quick Steps folder you just need to enumerate the items in the FAI collection by specifying an Associated Items traversal. eg the following code will return the existing Quick Step items

function Get-ExistingSteps{
  param(
  [Parameter(Position=0, Mandatory=$true)] [string]$MailboxName,
  [Parameter(Position=1, Mandatory=$true)] [Microsoft.Exchange.WebServices.Data.Folder]$QuickStepsFolder 
 )
 Begin
 {
  $NameList = @{}
  $enc = [system.Text.Encoding]::ASCII
  $PR_ROAMING_XMLSTREAM = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x7C08,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary);  
  $psPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)  
  $psPropset.Add($PR_ROAMING_XMLSTREAM)
  #Define ItemView to retrive just 1000 Items    
  $ivItemView =  New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)
  $ivItemView.Traversal = [Microsoft.Exchange.WebServices.Data.ItemTraversal]::Associated
  $fiItems = $null    
  do{    
      $fiItems = $QuickStepsFolder.FindItems($ivItemView)  
   if($fiItems.Items.Count -gt 0){
       [Void]$service.LoadPropertiesForItems($fiItems,$psPropset)  
       foreach($Item in $fiItems.Items){      
     $propval = $null
     if($Item.TryGetProperty($PR_ROAMING_XMLSTREAM,[ref]$propval)){
      [XML]$xmlVal = $enc.GetString($propval)
      if(!$NameList.ContainsKey($xmlVal.CombinedAction.Name.ToLower())){
       $NameList.Add($xmlVal.CombinedAction.Name.Trim().ToLower(),$Item)
      }
     }         
       }
   }    
      $ivItemView.Offset += $fiItems.Items.Count    
  }while($fiItems.MoreAvailable -eq $true) 
  return $NameList
 }
}

Export QuickStep XML

To Export the XML from a Quick Step Item you can grab the PR_Roaming_XMLStream property and then save this out to a file (it just plain XML) eg

function Export-QuickStepXML{
 param(
     [Parameter(Position=0, Mandatory=$true)] [string]$MailboxName,
  [Parameter(Position=1, Mandatory=$true)] [PSCredential]$Credentials,
  [Parameter(Position=2, Mandatory=$true)] [string]$Name,
  [Parameter(Position=3, Mandatory=$true)] [string]$FileName
 )
 Begin{
  #Connect
  $service = Connect-Exchange -MailboxName $MailboxName -Credential $Credentials
  $QuickStepsFolder = Get-QuickStepsFolder -MailboxName $MailboxName -service $service -Credentials $Credentials
  $ExistingSteps = Get-ExistingSteps -MailboxName $MailboxName -QuickStepsFolder $QuickStepsFolder
  if($ExistingSteps.ContainsKey($Name.Trim().ToLower())){
   $PR_ROAMING_XMLSTREAM = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x7C08,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary);  
   $psPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)  
   $psPropset.Add($PR_ROAMING_XMLSTREAM)
   $propval = $null
   if($ExistingSteps[$Name.Trim().ToLower()].TryGetProperty($PR_ROAMING_XMLSTREAM,[ref]$propval)){
    [System.IO.File]::WriteAllBytes($FileName,$propval)
    Write-Host ('Exported to ' + $FileName)
   }
  } 
 }
}

Creating a QuickStep from XML (Unsupported)

Note creating Quicksteps using anything other then Outlook should be considered unsupported so if you use this make sure you do your own testing. Creating a QuickStep from the XML is just a matter of creating an Item and setting the PR_Roaming_XMLStream property with the appropriate XML from the item. The following cmdlet first reads the existing Quicksteps to ensure your creating a Quickstep with the same name as an existing one. eg

function Export-QuickStepXML{
 param(
     [Parameter(Position=0, Mandatory=$true)] [string]$MailboxName,
  [Parameter(Position=1, Mandatory=$true)] [PSCredential]$Credentials,
  [Parameter(Position=2, Mandatory=$true)] [string]$Name,
  [Parameter(Position=3, Mandatory=$true)] [string]$FileName
 )
 Begin{
  #Connect
  $service = Connect-Exchange -MailboxName $MailboxName -Credential $Credentials
  $QuickStepsFolder = Get-QuickStepsFolder -MailboxName $MailboxName -service $service -Credentials $Credentials
  $ExistingSteps = Get-ExistingSteps -MailboxName $MailboxName -QuickStepsFolder $QuickStepsFolder
  if($ExistingSteps.ContainsKey($Name.Trim().ToLower())){
   $PR_ROAMING_XMLSTREAM = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x7C08,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary);  
   $psPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)  
   $psPropset.Add($PR_ROAMING_XMLSTREAM)
   $propval = $null
   if($ExistingSteps[$Name.Trim().ToLower()].TryGetProperty($PR_ROAMING_XMLSTREAM,[ref]$propval)){
    [System.IO.File]::WriteAllBytes($FileName,$propval)
    Write-Host ('Exported to ' + $FileName)
   }
  } 
 }
}

I've put all these samples into a QuickSteps EWS module which you can download from here some examples of what you can do with this

to Get the QuickSteps folder

Get-QuickStepsFolder -MailboxName mailbox@domain.com

To Get the existing Quick Steps

 Get-QuickSteps -MailboxName mailbox@domain.com

This returns a HashTable of the QuickSteps to access a Quickstep within the collection use the Index value eg
 $QuickSteps = Get-QuickSteps -MailboxName mailbox@domain.com
 $QuickSteps["clutter"]

To Delete and existing QuickStep

Delete-QuickStep -MailboxName gscales@datarumble.com -Name 'Task Name'

This cmdlet will search for a quickstep based on the Name attribute in the QuickSteps XML document if one is found it will prompt if you want to delete it.

Popular posts from this blog

The MailboxConcurrency limit and using Batching in the Microsoft Graph API

If your getting an error such as Application is over its MailboxConcurrency limit while using the Microsoft Graph API this post may help you understand why. Background   The Mailbox  concurrency limit when your using the Graph API is 4 as per https://docs.microsoft.com/en-us/graph/throttling#outlook-service-limits . This is evaluated for each app ID and mailbox combination so this means you can have different apps running under the same credentials and the poor behavior of one won't cause the other to be throttled. If you compared that to EWS you could have up to 27 concurrent connections but they are shared across all apps on a first come first served basis. Batching Batching in the Graph API is a way of combining multiple requests into a single HTTP request. Batching in the Exchange Mail API's EWS and MAPI has been around for a long time and its common, for email Apps to process large numbers of smaller items for a variety of reasons.  Batching in the Gr...

EWS-FAI Module for browsing and updating Exchange Folder Associated Items from PowerShell

Folder Associated Items are hidden Items in Exchange Mailbox folders that are commonly used to hold configuration settings for various Mailbox Clients and services that use Mailboxes. Some common examples of FAI's are Categories,OWA Signatures and WorkHours there is some more detailed documentation in the https://msdn.microsoft.com/en-us/library/cc463899(v=exchg.80).aspx protocol document. In EWS these configuration items can be accessed via the UserConfiguration operation https://msdn.microsoft.com/en-us/library/office/dd899439(v=exchg.150).aspx which will give you access to either the RoamingDictionary, XMLStream or BinaryStream data properties that holds the configuration depending on what type of FAI data is being stored. I've written a number of scripts over the years that target particular FAI's (eg this one that reads the workhours  http://gsexdev.blogspot.com.au/2015/11/finding-timezone-being-used-in-mailbox.html is a good example ) but I didn't have a gene...

Sending a MimeMessage via the Microsoft Graph using the Graph SDK, MimeKit and MSAL

One of the new features added to the Microsoft Graph recently was the ability to create and send Mime Messages (you have been able to get Message as Mime for a while). This is useful in a number of different scenarios especially when trying to create a Message with inline Images which has historically been hard to do with both the Graph and EWS (if you don't use MIME). It also opens up using SMIME for encryption and a more easy migration path for sending using SMTP in some apps. MimeKit is a great open source library for parsing and creating MIME messages so it offers a really easy solution for tackling this issue. The current documentation on Send message via MIME lacks any real sample so I've put together a quick console app that use MSAL, MIME kit and the Graph SDK to send a Message via MIME. As the current Graph SDK also doesn't support sending via MIME either there is a workaround for this in the future my guess is this will be supported.
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.