Parse Description of Transportrule to 1 line in Powershell

To get an overview of your Transport rules in or Exchange 2013 or Exchange 2016, the cmdlet Get-Transportrule is obviously the command to use.

However, if you want to generate a table with name and description only, you will find out the output is disappointing:

get-transportrule -Identity techniek | Select-object identity,description

It’s because the property “Description” is multi-lined that you only see the first few words. The rest of the text is in the lines below.
To list Identity and FULL description, you need to parse the property Description to 1 line.

I did some quick coding, nothing special or high-quality, but still effective:

#put the description of transport rule in a variable
$description = get-transportrule -Identity techniek | Select-object identity,description

# split the text into an array of lines
# the regex "(\r*\n){2,}" means 'split the whole text into an array where there are two or more linefeeds
$description1line = $description -split "(\r*\n){2,}"

#remove linefeeds for each section and output the contents
$description1line -replace '\r*\n', '' -replace '{Description=', ''

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x