Try the example below
Get-TransportRule "Test Rule" | select -ExpandProperty ExceptIfRecipientDomainIs | Export-Csv C:\myfile.csv
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
Try the example below
Get-TransportRule "Test Rule" | select -ExpandProperty ExceptIfRecipientDomainIs | Export-Csv C:\myfile.csv
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
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 : )