none
Creating and HTML report of Exchange Transport Rules for Disclaimer notices RRS feed

  • Question

  • I am working on creating and HTLM report for Disclaimer transport Rules for Exchange 2013.  Using the following code to do it.

    $a = "<style>"
    $a = $a + "BODY{font-family: Arial; font-Size: 10pt;}"
    $a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
    $a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
    $a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black}"
    $a = $a + "</style>"
    
    Get-TransportRule | Select Identity, @{L="Conditions";E={$_.Conditions}, @{L="Actions";E=$_.Actions}, FromScope, {$_.SenderADAttributeContainsWords}, ApplyHtmlDisclaimerLocation, ApplyHtmlDisclaimerText | ConvertTO-HTML -Head $a -body "<H2>Transport Rules</H2>"  > TransportRules.html

    The problem areas I am having though is the Conditions and Actions.  They show up like this.

    Conditions

    Microsoft.Exchange.MessagingPolicies.Rules.Tasks.FromScopePredicate Microsoft.Exchange.MessagingPolicies.Rules.Tasks.SenderAttributeContainsPredicate 

     Actions

    Microsoft.Exchange.MessagingPolicies.Rules.Tasks.ApplyHtmlDisclaimerAction

     

    I am trying to figure out what to put in the expression to only get the pieces after the Tasks part. 

     

     

     


    Jeff C

    Tuesday, June 17, 2014 4:02 PM

Answers

  • Thats because those properties are not flat.  What do you want to display?

    You can use something like this to look at your options:

    New-Object Microsoft.Exchange.MessagingPolicies.Rules.Tasks.FromScopePredicate | select *

    You'll need to call out the sub-property specifically.  For example, if you just wanted the name of the predicate, you'd use something like this:

    Get-TransportRule Rule1 | select identity, @{L="MyConditionName"; E={$_.Conditions.name}}



    Mike Crowley | MVP
    My Blog -- Planet Technologies

    • Proposed as answer by Mike Crowley Tuesday, June 17, 2014 4:55 PM
    • Marked as answer by JeffC72 Tuesday, June 17, 2014 9:45 PM
    Tuesday, June 17, 2014 4:54 PM

All replies

  • Thats because those properties are not flat.  What do you want to display?

    You can use something like this to look at your options:

    New-Object Microsoft.Exchange.MessagingPolicies.Rules.Tasks.FromScopePredicate | select *

    You'll need to call out the sub-property specifically.  For example, if you just wanted the name of the predicate, you'd use something like this:

    Get-TransportRule Rule1 | select identity, @{L="MyConditionName"; E={$_.Conditions.name}}



    Mike Crowley | MVP
    My Blog -- Planet Technologies

    • Proposed as answer by Mike Crowley Tuesday, June 17, 2014 4:55 PM
    • Marked as answer by JeffC72 Tuesday, June 17, 2014 9:45 PM
    Tuesday, June 17, 2014 4:54 PM
  • As an aside - here is an easier way to cast HTML into text:


    $style=@'
        <style>
             body{
                font-family: Arial; 
                font-Size: 10pt;
            }
            
            table{
                border-width: 1px;
                border-style: solid;
                border-color: black;
                border-collapse: collapse;
            }
    
            th{
                border-width: 1px;
                padding: 0px;
                border-style: solid;
                border-color: black;
                background-color:thistle
            }
            
            td{
                border-width: 1px;
                padding: 0px;
                border-style: solid;
                border-color: black
            }
        </style>
    @'
    $a=$style | Out-String
    I tend to place large blocks of text in a file and load into the variable as it keeps the actually code cleaner and more flexible.


    ¯\_(ツ)_/¯

    Tuesday, June 17, 2014 5:35 PM
  • Now take a look at your statement that uses calculated properties:

    Get-TransportRule | 
         Select Identity, 
                @{L="Conditions";E={$_.Conditions}, 
                @{L="Actions";E=$_.Actions}, 
                FromScope, 
                {$_.SenderADAttributeContainsWords}, 
                ApplyHtmlDisclaimerLocation, 
                ApplyHtmlDisclaimerText | 
          ConvertTO-HTML -Head $a -body '<H2>Transport Rules</H2>'  > TransportRules.html

    It is magnificently broken in almost every column.

    A computer column is this format:

    @{ Name='SomeName'; Expression={<expression>} }

    Expression is a code block "{}" and the whole object is a hash @{} which encloses to name/value pairs.

    Due to coerced matching we can shorten to this:

    @{N='SomeName';E={<expression>}}

    Expression is used to calculate or extract simple values.


    ¯\_(ツ)_/¯

    Tuesday, June 17, 2014 5:43 PM
  • Start with this and fix it by deciding how you want to parse "Conditions" which is a compound object.

    Get-TransportRule | 
         Select Identity, 
                @{N='Conditions';E={$_.Conditions}}, 
                @{N='Actions';E={$_.Actions[0].Text.Value}}, 
                FromScope,
                SenderADAttributeContainsWords, 
                ApplyHtmlDisclaimerLocation, 
                ApplyHtmlDisclaimerText

    Forget about HTML and output until you have figured out how to access the data.


    ¯\_(ツ)_/¯

    Tuesday, June 17, 2014 5:55 PM
  • "Forget about HTML and output until you have figured out how to access the data."


    I here you on this.. But just a side note.. The data shows up until you pipe it to ConvertTo-Html. Commonly see this with exchange parts and how you get it out is not always the same.  For Example in another instance I had to use a join expression.   

    Jeff C

    Tuesday, June 17, 2014 9:45 PM
  • Mike

    Thanks for pointing out the New-Object trick.  That helped a lot in finding the proper lines I needed.


    Jeff C

    Tuesday, June 17, 2014 9:47 PM
  • "Forget about HTML and output until you have figured out how to access the data."


    I here you on thirs.. But just a side note.. The data shows up until you pipe it to ConvertTo-Html. Commonly see this with exchange parts and how you get it out is not always the same.  For Example in another instance I had to use a join expression.   

    Jeff C

    You have to expand and select the individual properties and concatenate arrays.  I didn't rewrite the whole thing.  I just showed you where yu missed the boat and made some obvious syntax errors.  I feel it is best if you figure most of it out for yourself.


    ¯\_(ツ)_/¯

    Tuesday, June 17, 2014 10:02 PM