Boof
Boof

Reputation: 43

How to list all Resources in Exchange that has an "inbox rule" setup

I was wondering if someone can help me figure out the Powershell code needed to list the resource names of all resources / resource calendars in exchange that has "inbox rules" defined.

enter image description here

These inbox rules are accessible in ECP by going to "OTHER USER" and looking up the resource name, then under the Organize email selection, and inbox rules.

Preferably the result should be formated with

| ft -AutoSize | Out-File -Encoding Unicode h:\temp\rules.txt

I suspect it might be using the command Get-CalendarProcessing as we are on onpremises, not Office365.

If possible I would also like a script where i can use powershell to in bulk, go in and delete all these inbox rules for all resources where it exist.

Hope someone can help as i have been searching on google and all i can find is how to set it for a personal Mailbox, which the resources are not.

Best reg.

Boof

Upvotes: 0

Views: 1289

Answers (1)

Boof
Boof

Reputation: 43

How typical, you look through google for hours, then make a post here, and then come up with a different search criteria, and boom, you find a code you can alter to do what you want.

So found a webpage: https://community.spiceworks.com/topic/2145059-get-inboxrule-on-multiple-mailboxes?page=1#entry-7813880

It had code i could modify to get the results i wanted:

#Change the "test" text to any text the name of the resource start with
    Get-Mailbox -ResultSize unlimited | Where-Object {$_.DisplayName -match "^test.*"} | 
    foreach {
        Write-Verbose "Checking $($_.DisplayName)..." -Verbose
        $inboxrule = get-inboxrule -Mailbox $_.DisplayName  
        if ($inboxrule) {
            foreach($rule in $inboxrule){
            [PSCustomObject]@{
                Mailbox         = $_.DisplayName
                Rulename        = $rule.name
                Rulepriority    = $rule.priority
                Ruledescription = $rule.description
            }
        }
        }
    } | ft -AutoSize | Out-File -Encoding Unicode h:\temp\rules.txt

Result file looks like this:

Mailbox   Rulename          Rulepriority Ruledescription                                                                                                                 
-------   --------          ------------ ---------------                                                                                                                 
Test Room test rule for TWO            1 If the message:...                                                                                                              
Test Room test rule1                   2 If the message:...                                                                                                              

..showing all rules, for the meeting rooms.

Above only one, but when i changed to "56" as search wildcard above, it listed all the resource calendars which had inbox rules on it where the DisplayName started with "56"

Thought I'd leave it here, in case someone else wanted the code.

A small note, from what I found, it will not export data to txt file unless you use the Out-File command. I tried with CSV, but only gave garbage output

I used

-Encoding Unicode 

to allow for ÆØÅ letters in filenames to be visible in output.

| FT -AutoSize

will format it as a table and retain the full names of the names of the calendar/resourcenames.

Best reg

Boof

Upvotes: 0

Related Questions