0

I'm looking to create a PowerShell script that creates an Outlook rule which delays any email sent out by one minute.

I have very limited PowerShell knowledge and cannot find much information on this.

Here's what I have so far:

$olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
$outlook = New-Object -ComObject outlook.application
$namespace  = $Outlook.GetNameSpace("mapi")
$rules = $outlook.session.DefaultStore.GetRules()
$rule = $rules.Create("1MinDelay",$olRuleType::OlRuleSend)
$date = Get-Date
$date = $date.AddMinutes(1)
$mail.DeferredDeliveryTime = $date
$rules |
Sort-Object -Property ExecutionOrder |
Format-Table -Property Name, ExecutionOrder, Enabled, isLocalRule -AutoSize
ErikE
  • 4,676
  • 1
  • 19
  • 25
Jack
  • 1
  • 1
  • 3
  • 3
    Are you an Exchange administrator? There are a number of ways to do this. Also in line 8 of your code, you refer to the variable `$mail ` which doesn't appear to be set elsewhere. Should that say `$rule.DeferredDeliveryDate = $date`? Lastly, you haven't said what is not working about your code. – john Aug 13 '15 at 10:37
  • Hi John, I haven't got a clue why it doesn't work and what I require for it to work. That code is just something I've thrown together. – Jack Aug 17 '15 at 09:48

1 Answers1

0

olRuleActionDefer is not Supported when creating new rules programmatically,

As a workaround, try to create a new olRuleSend type rule and Apply the olRuleActionDefer to it, I have not tested it but i think it's possible

Creating Outlook rules through Powershell is explained and exemplified by The Scripting Guy here.

ErikE
  • 4,676
  • 1
  • 19
  • 25
Avshalom
  • 161
  • 7