How to obtain Major.Minor.Version.Patch details from PowerShell

Nitin Singh 20 Reputation points
2023-02-09T05:16:38.46+00:00

Hello everyone,

I happen to use following command to obtain operating system version details.

cmd /ver

The same command cannot be used when called in a PowerShell script like following. Why? because it opens a shell; and control remain stuck there.

invoke-command -scriptblock {cmd /ver}

Now I have tried following but this is not very explanatory as I want details given from cmd /ver.

$Version = (Get-CimInstance Win32_OperatingSystem -ErrorAction Stop).Version

How can I obtain the Major/Minor/Version/Patch details using any PowerShell command on a remote machine where the output from cmd /ver is equivalent to output from PowerShell command.

Output of cmd /ver

Microsoft Windows [Version 10.0.19044.2486]

(c) Microsoft Corporation. All rights reserved.

[Version 10.0.19044.2486] <---- is the details required via PowerShell, (meaning the numbers)

Output of Get-CimInstance Win32_OperatingSystem

10.0.19044

Any help would be appreciated.

Nitin.

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,811 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Andreas Baumgarten 117.7K Reputation points MVP
    2023-02-09T07:22:30.0433333+00:00

    Hi @Nitin Singh ,

    to get the version details of Windows you can try this:

    Get-ComputerInfo | Select-Object WindowsProductName,WindowsVersion, OsHardwareAbstractionLayer 
    

    The result will look like this

    Windows 10 Pro     2009           10.0.22621.819
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards Andreas Baumgarten

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.