Get Windows Server Edition using PowerShell and Export to CSV

Microsoft has its own business model for evolution of Software and Hardware products. Windows Servers belongs to one of them. It really earns good revenue in the terms of supporting IT infrastructure with their Software and Cloud-based solution. Being a user friendly and easy to maintenance, most of the giant companies prefer their products and services in ultimate way. If we talk alone about Windows Servers, it has already introduced Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, and Windows Server 2012, Windows Server 2012 R2 with various editions like Standard, Essentials, Enterprise and Datacenter on their own prospective. This year Microsoft has launched its new Windows Server 2016 which is advancement of various features and services of previous versions. Microsoft also provides support for these servers except Windows Server 2003. In this post we will try to find out the different Windows Server editions using its own automation tool known as PowerShell.

Get-Windows-Server-Edition-Using-PowerShell-And-Export-To-CSV


Download Script 1 downloads

PowerShell Script to get Windows Server Editions from the remote servers and Exporting to CSV File

We will access Win32_OperatingSystem class using Get-WmiObject

Command
(Get-WmiObject -class Win32_OperatingSystem -ComputerName "DESKTOP-G4BVD5L").Caption

Output
Microsoft Windows 10 Pro

This result was for your single local computer.

windows-time-service-and-powershell
Let's implement it for N no. of Servers

  Write-Host "Hi, This script will fetch Windows Server Editions " -ForegroundColor Cyan
$Location = Get-Content -Path Servers.txt
$ErrorActionPreference="silentlycontinue";
   foreach($Server in $Location)
{
   if($Server) {

$Server =$Server.Trim();
Write-Host  " ";
Write-Host  " ";
$query = "select * from win32_pingstatus where address = '$Server'"
$result = Get-WmiObject -query $query
Write-Host " "
Write-Host "Pinging the Server " $Server  -ForegroundColor yellow

  if ($result.protocoladdress) {

Write-Host "Pinged Recived Successfully" -ForegroundColor Green
Write-Host "Now Checking Server Edition of" $Server;
Write-Host  " ";
$EName=(Get-WmiObject -class Win32_OperatingSystem -ComputerName $Server).Caption

$SystemProps = [pscustomobject][ordered]@{
    ServerName       =$Server
    Edition_Name   =$EName

                                         }
                                  }

 else
       {
       Write-Host  " ";
       Write-Host "Failed to Ping the Server " $strComputer -ForegroundColor Red
       Write-Host  " ";
        $SystemProps = [pscustomobject][ordered]@{
    ServerName       =$Server
    Edition_Name   ="Failed To Ping "
                                                }

          }


$SystemProps
$SystemProps |
 Export-Csv  WindowsEditionName.Csv -Append -NoTypeInformation


}

        }

People Reaction : 1

Rohit Sharma
Name : Email : Website :
Rohit Sharma

Hi There! My name is Rohit and I am working in the one of MNC as Web Apps developer. I have been in this tech industry for last 3.6 years. This blog is just a part of my career journey.
Ready to make new mistakes without repeating the previous ones.

"All life is an experiment. The more experiments you make the better"


© 2020 WriteSomeCode. All Right Reserved. A Rohit Sharma Blog. Creative Commons License licensed under a Creative Commons Attribution 4.0 International License