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:
- SSH Enumeration and Penetration Testing – A Brief Guide
- How to Install Winlogbeat in Windows OS
- [Tutorial] How to Install MobSF on Kali Linux 2022.1
- How To Install Jenkins on Ubuntu Machine
- [Tutorial] How To Install Webmin in Ubuntu
- How to Install Apache Tomcat on Ubuntu Machine
- A Step-by-Step Guide to Installing the LAMP Stack on Ubuntu
- [Linux] MySQL: The Easy Way to Check Your Version
- How To Install Remmina in Ubuntu – A Remote Desktop Client
- Creating New Files and Directories Using Windows PowerShell New-Item CMDLET