Welcome to TechNet Blogs Sign in | Join | Help
Script para fazer inventário dos sistemas operacionais e service pack através do AD

O Active Directroy armazena uma série de informações dos objetos que pode ser utilizadas para, por exemplo, fazer um inventário de sistemas operacionais e service pack aplicado na sua empresa.

Para isso utilizo um script VBS que lê algumas destas propriedades dos objetos computadores e gera um arquivo TXT. Este arquivo texto pode ser importado para o Excel e através de uma Tabela dinâmica (Pivot Table) gerar um relatório semelhante a este.

Invent

No script abaixo, altere as linhas 5, informando o caminho completo onde será salvo o arquivo txt e a linha 16 com o caminho LDAP do seu domínio, no meu exemplo o domínio se chama hunecke.net.

Linha 5: Set objLogFile = objFSO.OpenTextFile("C:\windows\temp\Desk_OS.txt", ForAppending, True)

Linha 16: objCommand.CommandText = "Select Name, OperatingSystem, OperatingSystemServicePack from 'LDAP://DC=hunecke,DC=net' where objectClass='computer'"

rem --------------------------------------------

Const ADS_SCOPE_SUBTREE = 2
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("C:\windows\temp\Desk_OS.txt", ForAppending, True)
objLogFile.Write("ComputerName;OperationSystem;ServicePack")
objLogFile.WriteLine

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = "Select Name, OperatingSystem, OperatingSystemServicePack from 'LDAP://DC=hunecke,DC=net' where objectClass='computer'"
objCommand.Properties("Page Size") = 50000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF

objLogFile.Write(objRecordSet.Fields("Name").Value & ";")

If objRecordSet.Fields("OperatingSystem").Value <> " " Then
objLogFile.Write(objRecordSet.Fields("OperatingSystem").Value & ";")
else
objLogFile.Write(";")
End if

If objRecordSet.Fields("OperatingSystemServicePack").Value <> " " Then
objLogFile.Write(objRecordSet.Fields("OperatingSystemServicePack").Value)
End if

objRecordSet.MoveNext
objLogFile.WriteLine
Loop

objLogFile.WriteLine
objLogFile.WriteLine

rem --------------------------------------------

Posted: Wednesday, October 14, 2009 5:51 PM by mhunecke

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker