I have a Powershell script where I need to get the operating system for various servers. Up until now I've been using WMI in order to accomplish this task, however I've read about how WMI can get timeouts, so I was wondering is there another method of getting the operating system of a server? Here is the code that I use at the moment and want to change in order to avoid WMI:
$serverVersion = Get-WMIObject -computer $server -class Win32_OperatingSystem
Depending on how much granularity you need, you could also use .Net's System.Environment.OSVersion:
on windows:
on Linux (Ubuntu 18.04):
You will probably find what you are looking for in the registry. As of Windows 2000 the
ProductName
value can be found in this location:HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion
.To query this registry value using Powershell, try: