0

Normally , I can catch values beginning with Windows Server like below script. But I want to get version number for operating systems as well.

Windows Embedded
Windows XP
Windows 7  
Windows 10
Windows Server® 2008 Standard
Windows Server® 2008 Enterprise

So , it will be only 7 ,XP , 10 , Embedded , 2008 inside version variable.

Script :

$server = Get-ADComputer -Filter "Name -eq '$computer'" -Properties OperatingSystem -ErrorAction SilentlyContinue
$version = ([regex]'Windows Server (\d+)').Match($server.OperatingSystem).Groups[1].Value
2
  • There is an ® symbol, try Windows Server\D+(\w+) to match it and spaces, too. \w will match letters and digits (and _, too). Commented Feb 26, 2021 at 12:39
  • 1
    You could also try Windows(?: Server)?[^\w\r\n]+(\w+) regex101.com/r/iRhmJT/1 Commented Feb 26, 2021 at 12:42

1 Answer 1

1

This match every line and capture exactly what you want :

Windows(?: Server)?[^\w\r\n]+(\w+).*
Sign up to request clarification or add additional context in comments.

2 Comments

That is an awesome solution! :-) Note that just to get the value in the group, you can omit .*
I was wondering if PowerShell would still match the line without the .*, thank you for this precision ! :)

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.