Working as a System Admin, Sometimes you will need to know what operating systems of your server system for a specifc task. This is important query to support the report task becomes quicker. Today, I will show you a simple way to use PowerShell to find all your servers running Windows Server 2022 or any specific version.

What is PowerShell?

PowerShell is a tool that helps you automate tasks for managing computers. It uses commands, called cmdlets, to interact with your computer or network from a text-based interface.

Here’s a command that finds computers running Windows Server 2022 by using “Get-ADComputer” command :

Get-ADComputer -properties OperatingSystem -Filter * | Where-Object { $_.OperatingSystem -match "Windows Server 2022" } | Select-Object Name, OperatingSystem | Format-Table -AutoSize

Let’s understand each part:

  1. Get-ADComputer: This command gets information about computers from Active Directory, which is like a list of all the computers in your network ( You have to run the command: import-module active*  to import Active Directory library before using get-adcomputer)
  2. -properties OperatingSystem: This tells the command to look specifically for the operating system information of each computer.
  3. -Filter *: This means “get information about all computers.” The asterisk (*) is a wildcard that includes everything.
  4. | Where-Object { $_.OperatingSystem -match “Windows Server 2022” }: This part filters the list to only show computers that are running Windows Server 2022.
  5. | Select-Object Name, OperatingSystem: This selects just the name and operating system from the list, making it easier to read.
  6. | Format-Table -AutoSize: This makes the list into a table that fits your screen, making it neat and easy to read.

Why Use This Command?

  • Checking for Updates: Make sure all your servers are running the latest version or listing out of date OS version for further plan.
  • Security: Keep your servers safe by knowing what operating systems they are running.
  • Prepare for Changes: See which servers need updates or changes.
Share.
Leave A Reply

Exit mobile version