none
Automated audit and inventory from Active Directory RRS feed

  • Question

  • Hello everyone,

    I'd like to be able to run some type of script or program that can output the following:

    • Machine model number
    • Machine serial number
    • Machine OS version (XP or 7)

    I know that on each machine, you can run a prompt from cmd to get the model and serial numbers:

    • wmic bios get serialnumber
    • wmic csproduct get name

    I would just like to be able to get all of the device's info at once instead of manually going to each computer to find the info.

    Any help would be greatly appreciated.

    Thanks chaps!

    Sunday, November 17, 2013 12:46 AM

Answers

  • Sure, it's possible using the AD cmdlets. You can use Get-ADComputer to retrieve all computer objects from AD and then pass them through the ForEach loop instead. The example I'm posting below is targeted to a single OU, but you can just get every single computer object by removing -SearchBase blahblah. You may run into problems with that, so I do recommend pointing this at individual OUs instead.

    Import-Module ActiveDirectory

    Get-ADComputer -Filter * -SearchBase 'OU=TestOU,DC=domain,DC=com' | ForEach { $cs = Get-WmiObject Win32_ComputerSystem -ComputerName $_.Name $os = Get-WmiObject Win32_OperatingSystem -ComputerName $_.Name $bios = Get-WmiObject Win32_BIOS -ComputerName $_.Name $props = @{ 'Machine Name' = $cs.Name 'Manufacturer' = $cs.Manufacturer 'Model' = $cs.Model 'Operating System' = $os.Caption 'Serial Number' = $bios.SerialNumber } New-Object PsObject -Property $props } | Export-Csv .\machineAudit.csv -NoTypeInformation


    Here's a link to the Get-ADComputer syntax:

    http://technet.microsoft.com/en-us/library/ee617192.aspx

    EDIT: Also, you're very welcome. I'm just glad I saw this in the main thread stream.


    Don't retire TechNet! - (Maybe there's still a chance for hope, over 12,420+ strong and growing)


    • Edited by Mike Laughlin Wednesday, November 20, 2013 6:44 PM
    • Marked as answer by Jacorbello Thursday, November 21, 2013 2:01 AM
    Wednesday, November 20, 2013 6:43 PM

All replies

  • Hello,

    you can open cmd then type systeminfo.

    • Proposed as answer by Tony hedrich Monday, November 18, 2013 11:58 AM
    • Unproposed as answer by Jacorbello Monday, November 18, 2013 2:21 PM
    Monday, November 18, 2013 11:58 AM
  • I know that I can go to each machine and get the info that I need, what I'm trying to do is go onto our server (Server 2008 R2) and possibly do something with AD or PowerShell to get it to pull the OS version, model number and serial number from all of the computers on our domain. This way I can run a report instead of physically going to 800+ machines to get the info.
    Monday, November 18, 2013 2:23 PM
  • Hi,

    This will do what you're after:

    Get-Content .\machines.txt | ForEach {
    
        $cs = Get-WmiObject Win32_ComputerSystem -ComputerName $_
    
        $os = Get-WmiObject Win32_OperatingSystem -ComputerName $_
    
        $bios = Get-WmiObject Win32_BIOS -ComputerName $_
    
        $props = @{
            'Machine Name' = $cs.Name
            'Manufacturer' = $cs.Manufacturer
            'Model' = $cs.Model
            'Operating System' = $os.Caption
            'Serial Number' = $bios.SerialNumber
        }
    
        New-Object PsObject -Property $props
    
    } | Export-Csv .\machineAudit.csv -NoTypeInformation


    You may need to adjust the properties that are being used in the $props hashtable depending on the types of machines you'll be running this against. As an example, good data was returned for the two Dell machines I used during testing but it was unable to detect the model of my Lenovo laptop, since Lenovo saves this data in a different property entirely.

    I also suggestion posting any further questions you have like this in a more scripting focused forum, such as the Windows PowerShell or Scripting Guys forums.

    EDIT: I just reread this and figured I should add in some extra explanation, as I'm not sure what your comfort level is with PowerShell.

    This script reads in a list of machine names from a text file named machines.txt (which should be in the same directory as the script itself), then queries each machine via WMI to return the requested information. The results of this are then written to a CSV file which can be opened and easily sorted with Excel.


    Wednesday, November 20, 2013 5:20 AM
  • Thank you so much for this.

    I would like to know if there is a way to get it to pull the info directly from Active Directory Users and Computers instead of a separate txt file. If not, no worries.

    Wednesday, November 20, 2013 4:05 PM
  • Sure, it's possible using the AD cmdlets. You can use Get-ADComputer to retrieve all computer objects from AD and then pass them through the ForEach loop instead. The example I'm posting below is targeted to a single OU, but you can just get every single computer object by removing -SearchBase blahblah. You may run into problems with that, so I do recommend pointing this at individual OUs instead.

    Import-Module ActiveDirectory

    Get-ADComputer -Filter * -SearchBase 'OU=TestOU,DC=domain,DC=com' | ForEach { $cs = Get-WmiObject Win32_ComputerSystem -ComputerName $_.Name $os = Get-WmiObject Win32_OperatingSystem -ComputerName $_.Name $bios = Get-WmiObject Win32_BIOS -ComputerName $_.Name $props = @{ 'Machine Name' = $cs.Name 'Manufacturer' = $cs.Manufacturer 'Model' = $cs.Model 'Operating System' = $os.Caption 'Serial Number' = $bios.SerialNumber } New-Object PsObject -Property $props } | Export-Csv .\machineAudit.csv -NoTypeInformation


    Here's a link to the Get-ADComputer syntax:

    http://technet.microsoft.com/en-us/library/ee617192.aspx

    EDIT: Also, you're very welcome. I'm just glad I saw this in the main thread stream.


    Don't retire TechNet! - (Maybe there's still a chance for hope, over 12,420+ strong and growing)


    • Edited by Mike Laughlin Wednesday, November 20, 2013 6:44 PM
    • Marked as answer by Jacorbello Thursday, November 21, 2013 2:01 AM
    Wednesday, November 20, 2013 6:43 PM