Listor
Listor

Reputation: 93

Remove SMTP: from primary email address

How do I remove SMTP: from this statement, I want to parse this from the returning email address I have tried several methods and it always makes the entire field return blank.

@{Name = "PrimaryEmail"; Expression = { $_.ProxyAddresses.Where( { $_.StartsWith( 'SMTP:') } ) } }

Upvotes: 0

Views: 321

Answers (1)

AdminOfThings
AdminOfThings

Reputation: 25001

You can use the -creplace operator for this.

@{ Name = "PrimaryEmail"
   Expression = { $_.ProxyAddresses.Where( { $_.StartsWith( 'SMTP:') } ) -creplace '^SMTP:'}
}

-creplace is a case-sensitive version of replace. It works with array or string output. ^ matches the beginning of the current string. SMTP: is a literal match.

Upvotes: 2

Related Questions