0

I am getting the following error when trying to apply the following regex on this Exchange command.

@(Get-ExchangeServer | Format-List AdminDisplayVersion) | % { [regex]::Match($_, "^\sVersion (\d+\.\d+(\.\d+)?)\s").Success }

The command Get-ExchangeServer | Format-List AdminDisplayVersion returns the following:

[PS] C:\Windows\system32>Get-ExchangeServer | Format-List AdminDisplayVersion


AdminDisplayVersion : Version 14.0 (Build 442.3)

AdminDisplayVersion : Version 14.0 (Build 442.3)

And when applying the regex to it I get all false:

[PS] C:\Windows\system32>@(Get-ExchangeServer | Format-List AdminDisplayVersion) | % { [regex]::Match($_, "^\sVersion (\
d+\.\d+(\.\d+)?)\s").Success }
False
False
False
False
False
False

Any pointers as of what am I doing wrong?

3 Answers 3

1

AdminDisplayVersion is a Microsoft.Exchange.Data.ServerVersion object which has all of the version parts as properties. You can get the values directly without having to resort to string manipulation. If the Build part is what you;re looking for:

Get-ExchangeServer | Foreach-Object {$_.AdminDisplayVersion.Build}

Based on the above you can create a query like:

Get-ExchangeServer | Where-Object {$_.AdminDisplayVersion.Build -eq 123}
Sign up to request clarification or add additional context in comments.

1 Comment

Cool! that's fantastic, a lot more practical!
0

You have limited your regex to start with " Version" (^\sVersion). Here is correct one:

% { [regex]::Match($_, "\sVersion (\d+\.\d+(\.\d+)?)\s").Success }

Comments

0

Try changing your pattern in:

"\sVersion (\d+\.\d+(\.\d+)?)\s"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.