Monday, June 6, 2011

VBScript - Get Service Tags of All Dell PCs in Active Directory

I used to have access to Kaseya which will pull this for you, but my new employer doesn't use it.  This script has some issues (if a PC is offline it will just throw in the service tag of the last one) but it was quick and dirty enough for my purposes today.  I observe that Blogger doesn't handle code well, so beware of formatting.  I'll have to find a way around this and blog that.

'Pulls the Dell Service Tag or equivalent of every computer in AD and writes them to a text file with computer 'name
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set myFSO = CreateObject("Scripting.FileSystemObject")
Set WriteStuff = myFSO.OpenTextFile("C:\users\example\desktop\test.txt", 8, True)

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
Set WshShell = WScript.CreateObject("WScript.Shell")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name, Location from 'LDAP://DC=example,DC=corp' " _
        & "Where objectClass='computer'" 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    strComputer=objRecordSet.Fields("Name").Value
    Set objWMIService = GetObject("winmgmts:" & _
        "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    For Each objSMBIOS in objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")
        WriteStuff.WriteLine strComputer & " Serial Number: " & objSMBIOS.SerialNumber
    Next
    objRecordSet.MoveNext
Loop


WriteStuff.Close
SET WriteStuff = NOTHING
SET myFSO = NOTHING
MsgBox "Done"

Thursday, June 2, 2011

Old blog, new days

I'm intending this to be a chronicle of the daily struggles to be a good IT engineer as well as a running commentary on the technorati.  The migrations of our jobs to the cloud and overseas, fighting the long defeat against bad security, the slow erosion of our privacy, and all the other fun trends that make technology exciting.

Some days you'll get commentary; some days it'll be a link blog.

I'll try to do an appropriate level of page decoration here over the next few days.