Windows – How To List All Computers Operating System On A Network In Powershell

domainpowershellquerywindows

I am looking for a script to show all the machines, hostnames, and OS versions on my domain. I have found a few scripts, but none of the scripts that I have found will do both.

Here is an example of one that I have found:

$strCategory = "computer"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(objectCategory=$strCategory)")
$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
  $colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
  {$objComputer = $objResult.Properties; $objComputer.name}

Can someone please tell me how to create a script for powershell to list the hostname and operating system version?

Best Answer

To get OS Version:

 Get-ADComputer -Filter * -Property * | Format-Table Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion -Wrap –Auto

Get-ADComputer returns the computer name by default, as well.