Export Transport Rule in csv with column

asdf das 46 Reputation points

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 Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,432 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Roderick Bant 2,051 Reputation points

    Try the example below

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

  2. Rich Matheisen 45,416 Reputation points

    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" |
                "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,461 Reputation points

    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