diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/PSUserAgent.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/PSUserAgent.cs index 3b2b5792390..7fd144c3e34 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/PSUserAgent.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/PSUserAgent.cs @@ -6,6 +6,7 @@ using System.Management.Automation; using System.Runtime.InteropServices; using System.Globalization; +using System.Text.RegularExpressions; namespace Microsoft.PowerShell.Commands { @@ -131,7 +132,8 @@ internal static string PlatformName // only generate the windows user agent once if(s_windowsUserAgent == null){ // find the version in the windows operating system description - string versionText = OS.Substring(OS.LastIndexOf(" ") +1); + Regex pattern = new Regex(@"\d+(\.\d+)+"); + string versionText = pattern.Match(OS).Value; Version windowsPlatformversion = new Version(versionText); s_windowsUserAgent = $"Windows NT {windowsPlatformversion.Major}.{windowsPlatformversion.Minor}"; }