EWS Outlook Fast Steps Powershell the right way to

EWS Outlook Fast Steps Powershell the right way to Quickstep’s in Outlook is a characteristic that was added in Outlook in 2010 to assist automate repetitive duties you do with E-mail in Outlook. On this Submit I’ll undergo how one can manipulate the objects related to Fast steps utilizing EWS and PowerShell.

How Fast Steps are carried out in a Mailbox

The OuickSteps Folder is created by Outlook (eg no Outlook no folder) Within the Mailbox’s IPM Root as a hidden folder known as Fast Steps (with a FolderClass of IPF.Configuration) and inside this folder there are FAI (Folder Related Gadgets) which signify every of the QuickStep Gadgets. On every of these there’s a PidTagRoamingXmlStream property which comprises a ByteArray that represents an XMLDocument for every of the QuickStep gadgets for instance they give the impression of being one thing like

<?xml model="1.0"?>
<CombinedAction Ordinal="3200" Tooltip="" Icon="MoveToFolder" Identify="Clutter" Model="147153">
<ActionMoveToFolder>
<Folder>80010....06F006D0000000000</Folder>
</ActionMoveToFolder>
<ActionMarkAsRead>
</ActionMarkAsRead>
</CombinedAction>

Getting the QuickSteps Folder

To Get the QuickSteps folder (if it exists) you should utilize the PidTagAdditionalRenEntryIdsEx property on the IPM Root folder which can include the HexEntryId of the QuickSteps folder within the RSF_PID_COMBINED_ACTIONS PersistBlockType worth. Eg you are able to do this utilizing the next code

perform Get-QuickStepsFolder
{
param(
[Parameter(Place=0, Obligatory=$true)] [string]$MailboxName,
[Parameter(Place=1, Obligatory=$true)] [PSCredential]$Credentials,
[Parameter(Place=2, Obligatory=$false)] [Microsoft.Exchange.WebServices.Data.ExchangeService]$service
)
Start
{
if(!$service){
$service = Join-Trade -MailboxName $MailboxName -Credential $Credentials
}
$PidTagAdditionalRenEntryIdsEx = new-object Microsoft.Trade.WebServices.Information.ExtendedPropertyDefinition(0x36D9, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary)
$psPropset = new-object Microsoft.Trade.WebServices.Information.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$psPropset.Add($PidTagAdditionalRenEntryIdsEx)
$folderid= new-object Microsoft.Trade.WebServices.Information.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).Exchange("-","");
##Parse Binary Worth first phrase is Worth sort Second phrase is the Size of the Entry
$Sval = 0;
whereas(($Sval+8) -lt $hexVal.Size){
$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.Trade.WebServices.Information.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 Fast Steps Gadgets

The Fast Step gadgets are saved within the Folder Related Gadgets assortment of the Fast Steps folder. To get these utilizing EWS after you get the Fast Steps folder you simply have to enumerate the gadgets within the FAI assortment by specifying an Related Gadgets traversal. eg the next code will return the present Fast Step gadgets

perform Get-ExistingSteps{
param(
[Parameter(Place=0, Obligatory=$true)] [string]$MailboxName,
[Parameter(Place=1, Obligatory=$true)] [Microsoft.Exchange.WebServices.Data.Folder]$QuickStepsFolder
)
Start
{
$NameList = @{}
$enc = [system.Text.Encoding]::ASCII
$PR_ROAMING_XMLSTREAM = New-Object Microsoft.Trade.WebServices.Information.ExtendedPropertyDefinition(0x7C08,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary);
$psPropset= new-object Microsoft.Trade.WebServices.Information.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$psPropset.Add($PR_ROAMING_XMLSTREAM)
#Outline ItemView to retrive simply 1000 Gadgets
$ivItemView = New-Object Microsoft.Trade.WebServices.Information.ItemView(1000)
$ivItemView.Traversal = [Microsoft.Exchange.WebServices.Data.ItemTraversal]::Related
$fiItems = $null
do{
$fiItems = $QuickStepsFolder.FindItems($ivItemView)
if($fiItems.Gadgets.Rely -gt 0){
[Void]$service.LoadPropertiesForItems($fiItems,$psPropset)
foreach($Merchandise in $fiItems.Gadgets){
$propval = $null
if($Merchandise.TryGetProperty($PR_ROAMING_XMLSTREAM,[ref]$propval)){
[XML]$xmlVal = $enc.GetString($propval)
if(!$NameList.ContainsKey($xmlVal.CombinedAction.Identify.ToLower())){
$NameList.Add($xmlVal.CombinedAction.Identify.Trim().ToLower(),$Merchandise)
}
}
}
}
$ivItemView.Offset += $fiItems.Gadgets.Rely
}whereas($fiItems.MoreAvailable -eq $true)
return $NameList
}
}

Export QuickStep XML

To Export the XML from a Fast Step Merchandise you possibly can seize the PR_Roaming_XMLStream property after which save this out to a file (it simply plain XML) eg

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

Making a QuickStep from XML (Unsupported)

Notice creating Quicksteps utilizing something different then Outlook needs to be thought of unsupported so for those who use this be sure to do your individual testing. Making a QuickStep from the XML is only a matter of making an Merchandise and setting the PR_Roaming_XMLStream property with the suitable XML from the merchandise. The next cmdlet first reads the present Quicksteps to make sure your making a Quickstep with the identical title as an current one. eg

perform Export-QuickStepXML{
param(
[Parameter(Place=0, Obligatory=$true)] [string]$MailboxName,
[Parameter(Place=1, Obligatory=$true)] [PSCredential]$Credentials,
[Parameter(Place=2, Obligatory=$true)] [string]$Identify,
[Parameter(Place=3, Obligatory=$true)] [string]$FileName
)
Start{
#Join
$service = Join-Trade -MailboxName $MailboxName -Credential $Credentials
$QuickStepsFolder = Get-QuickStepsFolder -MailboxName $MailboxName -service $service -Credentials $Credentials
$ExistingSteps = Get-ExistingSteps -MailboxName $MailboxName -QuickStepsFolder $QuickStepsFolder
if($ExistingSteps.ContainsKey($Identify.Trim().ToLower())){
$PR_ROAMING_XMLSTREAM = New-Object Microsoft.Trade.WebServices.Information.ExtendedPropertyDefinition(0x7C08,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary);
$psPropset= new-object Microsoft.Trade.WebServices.Information.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$psPropset.Add($PR_ROAMING_XMLSTREAM)
$propval = $null
if($ExistingSteps[$Identify.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 right into a QuickSteps EWS module which you’ll be able to download from right here some examples of what you are able to do with this

to Get the QuickSteps folder

Get-QuickStepsFolder -MailboxName mailbox@area.com

To Get the present Fast Steps

 Get-QuickSteps -MailboxName mailbox@area.com

This returns a HashTable of the QuickSteps to entry a Quickstep inside the assortment use the Index worth eg
 $QuickSteps = Get-QuickSteps -MailboxName mailbox@area.com
 $QuickSteps[“clutter”]

To Delete and current QuickStep

Delete-QuickStep -MailboxName gscales@datarumble.com -Identify ‘Job Identify’

This cmdlet will seek for a quickstep primarily based on the Identify attribute within the QuickSteps XML doc if one is discovered it should immediate if you wish to delete it.

Leave a Reply