Arbelac
Arbelac

Reputation: 1904

Powershell getting values via regex

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

Upvotes: 0

Views: 47

Answers (1)

user15242289
user15242289

Reputation:

This match every line and capture exactly what you want :

Windows(?: Server)?[^\w\r\n]+(\w+).*

Upvotes: 1

Related Questions