Export Transport Rule in csv with column

asdf das 46 Reputation points
2021-09-10T14:20:53.55+00:00

Hi,
need to export domainlist of O365 transport rule to a csv but with columns.
This code works:

$domain= Get-TransportRule "Test Rule" | select -ExpandProperty ExceptIfRecipientDomainIs | out-file C:\myfile.csv

but I need two Columns inside CSV, the first "Column 1" that contains results of $domain, the second Column 1 that contain the name of the Rule "Test Rule" for each record

How can i achieve this?

thanks so much

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Roderick Bant 2,056 Reputation points
    2021-09-10T14:41:52.407+00:00

    Try the example below

    Get-TransportRule "Test Rule" | select -ExpandProperty ExceptIfRecipientDomainIs | Export-Csv C:\myfile.csv


  2. Rich Matheisen 47,901 Reputation points
    2021-09-10T22:50:40.317+00:00

    I don't have an Exchange organization in which to try this, so I'm not sure what the results will be from the Select-Object (i.e. an array or a comma-separated string), or if "Name" is the correct property name in the transport rule object, but give this a try and see if it helps:

    Get-TransportRule "Test Rule" |
        ForEach-Object{
            [PSCustomObject]@{
                "Domain(s)" = (Select-Object -ExpandProperty ExceptIfRecipientDomainIs) -join ";"
                # Or this:
                # "Domain(s)" = (Select-Object -ExpandProperty ExceptIfRecipientDomainIs) -Split(",") | -join ";"
                "Rule Name" = $_.Name
            }
        } | Export-CSV C:\myfile.csv -NoTypeInformation
    

  3. Limitless Technology 39,916 Reputation points
    2021-09-13T10:30:19.057+00:00

    Hello Asdfdas,

    Export-TransportRuleCollection, This cmdlet is available in on-premises Exchange and in the cloud-based service. Some parameters and settings may be exclusive to one environment or the other.

    Use the Export-TransportRuleCollection cmdlet to export the transport rules in your organization.

    In your case try having a look with "ExpandProperty ExceptIfRecipientDomainIs" and in the rule name string check whether it is rightly mentioned.

    To see the return types, which are also known as output types, that this cmdlet accepts, see Cmdlet Input and Output Types. If the Output Type field is blank, the cmdlet doesn't return data.

    Hope this answers all your queries, if not please do repost back.
    If an Answer is helpful, please click "Accept Answer" and upvote it : )

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.