locked
PowerShell Script to Activate/deactivate Outlook rule RRS feed

  • Question

  • Hello,

    we have an employee who is going to be out of the office every Friday.

    I was wondering, is there a way to activate and deactivate a rule with PowerShell.
    The rule in question is a forward rule, all of her emails are going to be forwarded to another employee.
    So instead of activating and deactivating the rule manually, Im thinking of doing a PS script and add it to Scheduled task to run every Thursday 23:59 and Friday 23:59

    • Moved by Bill_Stewart Monday, November 30, 2015 4:08 PM Off-topic
    Thursday, October 22, 2015 9:28 AM

Answers

  • Hi,
    is it possible to use something like this "save credentials" to access O365?
    I want my script to look something like this so It can be automated.

    1) read-host -assecurestring | convertfrom-securestring | out-file C:\cred.txt

    2) $password = get-content C:\cred.txt | convertto-securestring

    3) $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist "myusername",$pass

    4) $UserCredential = Get-Credential (WANT TO SKIP THIS STEP)

    5) $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

    6) Import-PSSession $Session

    7) Set-Mailbox "From" -ForwardingAddress  "To@domain.com" -DeliverToMailboxAndForward $true (to Activate rule)

    8) Set-Mailbox "From" -ForwardingAddress  $null (to Deactivate r
    • Marked as answer by Jannis.F Thursday, April 14, 2016 11:12 AM
    Wednesday, October 28, 2015 9:37 AM

All replies

  • What is the question?


    \_(ツ)_/

    Thursday, October 22, 2015 9:48 AM
  • "I was wondering, is there a way to activate and deactivate a rule with PowerShell?"
    Thursday, October 22, 2015 1:24 PM
  • Yes. You can "turn on" and "turn off" the rule.

    A little search and the answer pops up. http://www.slipstick.com/developer/enable-or-disable-rule-using-reminder-and-vba/


    \_(ツ)_/

    Thursday, October 22, 2015 1:34 PM
  • Thursday, October 22, 2015 1:35 PM
  • Hi,
    is it possible to use something like this "save credentials" to access O365?
    I want my script to look something like this so It can be automated.

    1) read-host -assecurestring | convertfrom-securestring | out-file C:\cred.txt

    2) $password = get-content C:\cred.txt | convertto-securestring

    3) $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist "myusername",$pass

    4) $UserCredential = Get-Credential (WANT TO SKIP THIS STEP)

    5) $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

    6) Import-PSSession $Session

    7) Set-Mailbox "From" -ForwardingAddress  "To@domain.com" -DeliverToMailboxAndForward $true (to Activate rule)

    8) Set-Mailbox "From" -ForwardingAddress  $null (to Deactivate r
    • Marked as answer by Jannis.F Thursday, April 14, 2016 11:12 AM
    Wednesday, October 28, 2015 9:37 AM
  • Step 4 can be skipped with the rest as is. I have a scheduled task running a script for something very similar, using the exact method you have outlined, and it works well. For reasons I cannot remember, for step 6 I have "$importsession = Import-PSSession $Session".


    Wednesday, October 28, 2015 3:57 PM