When managing server operating systems, it is important to have information about the specific operating system name and version. This information can be useful for troubleshooting, ensuring compatibility with software or hardware requirements, and keeping track of system updates. In this blog post, we will explore a script that can be used to retrieve the operating system name and version of server operating systems.

To begin with, let’s take a look at the script provided:

$servers = @("Exch1", "Exch2", "Exch3")

The script above initializes an array called “$servers” with the names of three servers: “Exch1”, “Exch2”, and “Exch3”. You can modify this array to include the names of the servers you want to retrieve the operating system information from.

Now, let’s proceed with the script that will help us generate the desired information:

$servers = @("Exch1", "Exch2", "Exch3")  # Add your server names here

$results = @()

foreach ($server in $servers) {
    $output = Invoke-Command -ComputerName $server -ScriptBlock {
        systeminfo | Select-String -Pattern "Host Name", "OS Name", "OS Version"
    }
    
    $result = New-Object PSObject -Property @{
        "Server" = $server
        "Host Name" = $output | Where-Object { $_ -match "^Host Name" } | ForEach-Object { ($_ -split ":")[1].Trim() }
        "OS Name" = $output | Where-Object { $_ -match "^OS Name" } | ForEach-Object { ($_ -split ":")[1].Trim() }
        "OS Version" = $output | Where-Object { $_ -match "^OS Version" } | ForEach-Object { ($_ -split ":")[1].Trim() }
    }
    
    $results += $result
}

$results | Format-Table -AutoSize

The script above uses PowerShell’s Invoke-Command cmdlet to retrieve the operating system information for each server specified in the “$servers” array. Let’s break down the script step by step:

  1. The foreach loop iterates over each server name in the “$servers” array.
  2. Within the loop, the Systeminfo cmdlet is used to retrieve the operating system information for the current server. The -ComputerName parameter is used to specify the remote server from which to retrieve the information.
  3. The retrieved operating system information is then stored in the variables “$osName” and “$osVersion”. The Caption property of the $osInfo object represents the operating system name, while the Version property represents the operating system version.
  4. The Format-Table cmdlet is used to display the server name, operating system name, and version on the console. You can modify this part of the script to store the information in a file or perform any other desired action.

Here is the output of running the script, it works in PowerShell ISE, PowerShell and the Exchange Management Shell (EMS):

How to retrieve the operating system name and version of server operating systems

By running the script, you will be able to retrieve the operating system name and version for each server specified in the “$servers” array. This information can be valuable for managing and maintaining your server infrastructure.

Remember to replace the server names in the “$servers” array with the actual names of the servers you want to retrieve the information from. Additionally, ensure that you have the necessary permissions and network connectivity to access the remote servers.

That’s it! You now have a script that can help you retrieve the operating system name and version of server operating systems. Feel free to customize the script according to your specific requirements and use cases.

    wpChatIcon

    Discover more from Everything-PowerShell

    Subscribe now to keep reading and get access to the full archive.

    Continue reading