Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language. It was first released in 2006 and it is built on top of the .NET framework.
PowerShell allows system administrators to automate tasks, manage and control Windows-based systems and perform administrative tasks in a more efficient and consistent manner. It is also used for managing and automating various Microsoft products like Exchange Server, SharePoint Server, and Skype for Business.
To retrieve the version number of the operating system in PowerShell, you can use the below methods:
Method 1 – The version of OS can be determined by running the following command in a PowerShell prompt:
This will return the version number of PowerShell installed on the system, such as Major.Minor. Build. Revision.
Method 2 – If you only want specific property values, the Get-ComputerInfo command is one of the quickest methods of getting specific system information, like your Windows version. The Get-ComputerInfo cmdlet in PowerShell is used to retrieve information about the computer and its configuration.
By using the Select-Object cmdlet with the WindowsProductName, WindowsVersion, and OsHardwareAbstractionLayerVersion properties, you can display specific information about the operating system.
Command: Get-ComputerInfo | Select-Object WindowsProductName, WindowsVersion, OsHardwareAbstractionLayerVersion
Method 3 – Another way to get the Windows version is through the System.Environment class. This class provides access to system information, such as the OS version, username, and other environment variables.
The [System.Environment]::OSVersion.Version expression in PowerShell is used to retrieve the version of the operating system that the script is running on. This expression returns a Version object that contains information about the major, minor, build, and revision numbers of the operating system.
Method 4 – PowerShell cmdlets provide a handful of information about your system. But if you only plan to get your Windows version, the Get-ItemProperty cmdlet is another option. This cmdlet command lets you access the registry and get various properties from it.
Command: (Get-ItemProperty “HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion”).ReleaseId
The ReleaseId property contains the version number of the operating system.
Method 5 – The Get-CimInstance cmdlet is another way to get your Windows version by querying Windows Management Instrumentation (WMI) objects. Doing so lets you access various properties from your system hardware.
Command: (Get-CimInstance Win32_OperatingSystem).version
This will return the version number of the operating system, such as 10.0.22621.
In conclusion, there are several ways to retrieve the version number of the operating system in PowerShell. Each method provides a different approach to retrieve information about the operating system, and it depends on the specific requirements and the intended use of the script to determine which method is the best fit.
You may also read:
- How To Check Which Apps are Sending Information
- How To Use chattr Command in Linux
- [Two Methods] Force Linux User to Change Password at Next Login
- How To Install The WinDbg Windows Debugging Tool
- Getting Started with Apache Solr on Ubuntu
- Understanding OpenSSL Commands – A Comprehensive Guide
- How To Check SSL Certificate Expiry Date from Certificate File
- How To Install Apache Tomcat on Ubuntu 22.04 LTS
- How To Compress Files Faster Using Pigz on Ubuntu Linux
- A Step-by-Step Guide to Setting up Nginx and SSL with Certbot