How to create an Exchange Web Services Listener via PowerShell

RJames2010 36 Reputation points
2023-06-09T00:43:18.0166667+00:00

I have a mailbox for a service account which uses scheduled tasks to scrape the mailbox using Exchange Web Services. This all works well, but I want to be able to use this mailbox for SOAR. I need to create a listener using EWS via PowerShell (sorry, I'm not a developer but can do .NET via PS) so that when emails come in, I can automate actions. I haven't attempted this yet but also haven't found any documentation on how to make this happen. I want this listener to work 24x7. Once I figure out how to create the listener, I will be able to have it take actions on any new emails - that part shouldn't be a problem - but I'm just not certain how to create the listener itself. Any help is much appreciated.

Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
512 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,360 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,091 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Limitless Technology 43,966 Reputation points
    2023-06-09T12:31:09.85+00:00

    Hello there,

    This is made possible by the .NET HttpListener.

    1. Create and Start the HTTP Listener

    $httpListener = New-Object System.Net.HttpListener

    $httpListener.Prefixes.Add('http://localhost:5001/')

    $httpListener.Start()

    Here, I’m listening for requests aimed at http://localhost:5001/, but you could listen to any other interface or port on your machine.

    Listen on all interfaces by using a +, like so: http://+:5001/

    HttpListener requires that you include a trailing / in the prefix.

    In a separate PowerShell session:

    Invoke-WebRequest 'http://localhost:5001/big-test'

    You could kick off a request from anywhere though. It doesn’t have to be from PowerShell or even from your machine.

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer–


  2. RJames2010 36 Reputation points
    2023-06-15T11:43:54.4333333+00:00

    So, I went a different route and created a subscription in EWS which is now working. Thanks for your help!

    0 comments No comments

  3. Jarvis Sun-MSFT 10,091 Reputation points Microsoft Vendor
    2023-06-16T09:11:33.7633333+00:00

    @RJames2010

    Glad to see that your issue had already been resolved and thanks for sharing the solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others", I'll repost your solution in case you'd like to "Accept" the answer.

     

     

     

    [How to create an Exchange Web Services Listener via PowerShell]

     

    Issue Symptom:

    I need to create a listener using EWS via PowerShell (sorry, I'm not a developer but can do .NET via PS) so that when emails come in, I can automate actions.

     

    Solution:

    I went a different route and created a subscription in EWS which is now working.

    Best regards,

    0 comments No comments