Get WMI info from OU server collection

Welcome Forums General PowerShell Q&A Get WMI info from OU server collection

This topic contains 3 replies, has 3 voices, and was last updated by

1 year, 12 months ago.

  • Author
  • #67398

    Points: 14
    Rank: Member

    I have a simple problem, I need to know what servers are still running server 2008/R2.

    I know that win32_operatingsystem's "name" property contains the information that I'm looking for. I would like to be able to run Get-WmiObject against a collection of servers in an OU.

    There are two problems that I'm having:
    1) I can't figure out how to redirect the output of Get-ADComputer to something that Get-WmiObject -computername can use. I'm new to PowerShell but I think the Get-ADComputer is outputting TypeName: Microsoft.ActiveDirectory.Management.ADComputer and Get-WmiObject is looking for TypeName: System.Management.ManagementObject properties. Here's what I came up with but it doesn't appear to work.

    Get-WmiObject win32_operatingsystem -ComputerName (Get-ADComputer -filter * -SearchBase "OU=Member Servers,DC=Company,DC=Com" | select @{L="ComputerName";e={$_."name"}}) -Property name, csname | select csname, name | Format-Table -AutoSize

    2) My temp workaround: I was able to create a CSV that contains the list of server names. I was able to use the CSV to run Get-WmiObject against. However, the OU contains "dead" servers. So when I try to run get-wmiobject using the CSV-list of servers that came from AD there are connection timeouts and PowerShell waits a period of time to see if the dead server will respond. This really slows down the operation & we are working to clean this up. Until that happens, Is there a way to only pass the server names that pass a test-connection to Get-WmiObject?

    Get-WmiObject win32_operatingsystem -ComputerName (Get-Content C:\Users\user1\Desktop\Servers.csv) -Property name, csname | select csname, name | Format-Table -AutoSize

    Thanks for your time.

  • #67498

    Points: 1
    Rank: Member

    I'm a little surprised no one has responded to this one yet. My first question is, do you have a specific reason for wanting to use WMI to reach out to each remote system and get the operating system version? The operating system is stored as part of the Active Directory object, so you could just pull the OSs from AD

    Get-ADComputer -Filter * -Properties OperatingSystem

    Furthermore, you can filter the results to just 2008 systems

    Get-ADComputer -Filter "OperatingSystem -like '*2008*'" -Properties OperatingSystem | Select-Object Name, OperatingSystem
  • #67567

    Points: 0
    Rank: Member

    Your original code wouldn't work because Get-WmiObject -Computername parameter expects an array of strings – each string contains a computername.
    This would work

    Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName (Get-ADComputer -Filter * -SearchBase 'OU=Servers,DC=Manticore,DC=org' | select -ExpandProperty Name) |
    select CSName, Caption

    I use the CIM cmdlets because they work over WSMAN rather than DCOM.

    using Caption because Name is shows both OS (from caption) and system device

    Get-ADcomputer does return Operating System but that assumes that you AD is up to date and unneeded computer accounts are removed. My experience is that most organisations don't keep their AD clean. use WMI in this way means that your getting information from machines you know exist because you've contacted them

  • #67680

    Points: 14
    Rank: Member

    Thanks Curtis & Richard.

    The reason I didn't go with checking AD for the OS is because the OU that I'm checking hasn't been well maintained. I thought by using WMI I would be checking a live server for its OS.

    Thanks Richard. I hadn't thought to use CIM – which worked well! I think I will continue using it for things like this.

    I really appreciate both of your help. Its nice getting feedback from more experienced users who can help point the rookies (like me) in the right direction.

The topic ‘Get WMI info from OU server collection’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort