Okay so a visitor to Microsoft PowerShell forums asked how to set Microsoft Outlook to cast a message with a warning if a mail contained an attachment. I wrote a quick hack for him and I thought I would share it with anyone who is reading this blog or (more likely) stumbled in here from Google. Here you go.
$outlook = New-Object -ComObject outlook.application $rules = $outlook.Session.DefaultStore.GetRules() $olRuleType = "Microsoft.Office.Interop.Outlook.OlRuleType" -as [type] $rule = $rules.Create("MyNewRule",$olRuleType::OlRuleReceive) $FromCondition = $rule.Conditions.HasAttachment $FromCondition.Enabled = $true $RuleAction = $rule.Actions.NewItemAlert $RuleAction.Text = "This is a demo script" $RuleAction.Enabled = $true $rules.Save()
The script generates a warning that looks like this