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:
Command: .\\systeminfo
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.
Command: [System.Environment]::OSVersion.Version
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.
Conclusion –
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 like:- Understanding Netstat – The Network Monitoring Tool
- Using Elasticsearch Ingest Pipeline to Copy Data from One Field to Another
- Top 10 Useful Windows Commands
- Essential Commands For Process Management in Kali Linux
- How To Install Python 2.7.18 From The Source
- How To Parse SSH Authentication Logs with Logstash
- How To Easily Crack Wi-Fi Password
- 6 Most Useful Windows Command Prompt Commands
- Ripgrep – Searching for Specific File Types and Beyond
- Insert and Create Data in Elasticsearch