#* FileName: GetMachineSN.ps1 #*============================================================================= #* Script Name: [GetMachineSN] #* Created: [10/15/07] #* Author: Steven Murawski #* Company: #* Email: steve@acoupleofadmins.com #* Web: http://www.acoupleofadmins.com #* Reqrmnts: #* Keywords: #*============================================================================= #* Purpose: To remotely retrieve the serial numbers of all computers in an #* Active Directory Domain #* #*============================================================================= #*============================================================================= #* REVISION HISTORY #*============================================================================= #* Date: [DATE_MDY] #* Time: [TIME] #* Issue: #* Solution: #* #*============================================================================= #*============================================================================= #* SCRIPT BODY #*============================================================================= # Type of object to retrieve from AD $strCategory = "computer" # Set the domain to search to be the current domain $objDomain = New-Object System.DirectoryServices.DirectoryEntry # Find all the objects in the domain with the category of Computer $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $objDomain $objSearcher.Filter = ("(objectCategory=$strCategory)") # Array of property types to retrieve $colProplist = "name" foreach ($i in $colPropList) { $a = $objSearcher.PropertiesToLoad.Add($i) } # Finds all the computers in the domain and # saves them to a collection $colResults = $objSearcher.FindAll() # iterate through the collection foreach ($objResult in $colResults) { # Set an object with the properties of search result (name and adspath) $objComputer = $objResult.Properties # Ping the computer to see if it is live on the network $ping = New-Object System.Net.NetworkInformation.Ping $reply = $ping.send($objComputer.name) # if the computer is live, get the serial number via WMI if ($reply.status -eq "Success") { $QueryString = Get-WmiObject Win32_SystemEnclosure -Comp $objComputer.name $Serial = $QueryString.SerialNumber Write-Host $objComputer.name ":" $Serial } # if the computer does not respond, print a default message else { Write-Host $objComputer.name ": Not online" } } # Reset the default error handling $ErrorActionPreference = "continue" #*============================================================================= #* END OF SCRIPT: [GetMachineSN.ps1] #*=============================================================================