bandgeekmafia78 Posted May 17, 2011 Posted May 17, 2011 Hi. I've found a script to do this for 1 computer at a time but does anyone know how to change this to find ALL serial numbers in one go? ComputerName = InputBox("Enter the name of the computer you wish to query") winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &"" 'WScript.Echo winmgmt1 Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS") for each SN in SNSet MsgBox "The serial number for the specified computer is: " & SN.SerialNumber Next Any help would be much appreciated! Alan.
Steve21 Posted May 17, 2011 Posted May 17, 2011 Dim myArray(3) myArray(0) = "BoB1" myArray(1) = "BoB2" myArray(2) = "BoB3" myArray(3) = "BoB4" For i = 0 To UBoundmyArray ComputerName = myArrayi winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &"" 'WScript.Echo winmgmt1 Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS") for each SN in SNSet MsgBox "The serial number for the specified computer is: " & SN.SerialNumber Next Next Is the basic code that should work, obviously need to populate the arrays etc. Steve 2
FN-GM Posted May 17, 2011 Posted May 17, 2011 Not sure about yours but this will find all the serial numbers and dump them into a CSV file http://www.edugeek.net/forums/scripts/32287-inventory-your-network.html 2
TimmG6376 Posted May 23, 2011 Posted May 23, 2011 $ErrorActionPreference = "SilentlyContinue" #Replace with your computer OU $OU = "OU=Computers,DC=domain,DC=local" $LdapFilter = "(&(objectCategory=computer))" $objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://"+$OU) $objADsearcher = New-Object System.DirectoryServices.DirectorySearcher $objADsearcher.SearchRoot = $objDomain $objADsearcher.filter = "$LdapFilter" $colProplist = "cn" foreach ($i in $colPropList){$objADsearcher.PropertiesToLoad.Add($i)} $objResults = $objADsearcher.findall() $AllComputers = @() $ComputerObj = @() $ComputerObj = New-Object psObject Foreach ($objresult in $objResults ) { $ComputerObj = @() $ComputerObj = New-Object psObject $CN = ($objResult.GetDirectoryEntry().cn).ToString().TrimEnd() $ComputerObj | Add-Member -MemberType NoteProperty -Name "CN" -Value $CN -Force If ($result = test-connection -computername $CN -Quiet -Count 2 -TimeToLive 5){ $ComputerObj | Add-Member -MemberType NoteProperty -Name "Model" -Value ((Get-WmiObject -class win32_computersystem -computername $CN).model) -Force $ComputerObj | Add-Member -MemberType NoteProperty -Name "Manufacturer" -Value ((Get-WmiObject -class win32_bios -computername $CN).manufacturer) -Force $ComputerObj | Add-Member -MemberType NoteProperty -Name "Serial" -Value ((Get-WmiObject -class win32_bios -computername $CN).serialnumber) -Force } Else { $ComputerObj | Add-Member -MemberType NoteProperty -Name "Model" -Value "Not Found" -Force $ComputerObj | Add-Member -MemberType NoteProperty -Name "Manufacturer" -Value "Not Found" -Force $ComputerObj | Add-Member -MemberType NoteProperty -Name "Serial" -Value "Not Found" -Force } $ComputerObj | ft $AllComputers += $ComputerObj } $file = "ComputerInventory_" + (Get-Date -Format "yyyyMMdd") + ".csv" $AllComputers |Sort-Object "CN" | Export-Csv "$file" -NoTypeInformation Requires Powershell. I'm using 2.0 but I don't think there is anything in there that won't work in 1.0. Haven't tested for backwards compatibility. Finds computers in AD using designated OU as starting point. Sends ping to verify host is online before querying WMI. Exports results to CSV. Having an issue with a couple of PCs where access to WMI is being denied. In these cases the fields for Model, Serial, Manufacturer will be blank instead of "Not Found". I imagine it is an issue with WMI on those workstations and will have to investigate.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now