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

Solution 1:

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.

Solution 2:

Not sure if this is exactly what you are looking for, but it works for me. You need to know the computer name which you pass into the function. And it will give you the OS in the return string. I'm sure it could be modified to suit other needs.

function global:Get-OSInfo

    [string] $strReturn = '' 

    if([string]::IsNullOrEmpty($computer) -eq $false)
        # Create the connection to Active directory.
        $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
        $root = $dom.GetDirectoryEntry()
        $search = [System.DirectoryServices.DirectorySearcher]$root

        # Search the directory for our user.
        $search.Filter = "(&(objectclass=Computer)(sAMAccountName=$computer$))"
        $result = $search.FindOne()

        if ($result -ne $null)
            $system = $result.GetDirectoryEntry()
            $strReturn = $system.Properties["operatingSystem"]

    return $strReturn