Mark Minasi's Reader Forum
Mark Minasi's Reader Forum
Home | Profile | Register | Active Topics | Active Polls | Members | Search | FAQ | Minasi Forum RSS Feed
 All Forums
 HALP! Questions on Windows and Windows Server
 Scripting
 A script to inventory everything server related

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Note: please do not cross-post.
Cross-postings will be deleted and ignored.
Thanks for helping to keep this forum junk-free!
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Phil Marcum Posted - 07/20/2010 : 6:37:36 PM
Anyone have a script to display hw & sw inventory on vmware, linux, and windows servers ? Basically I'd like to capture the OS of the server and any programs that may be running to include basic hardware info, and distinguish between it being physical or virtual. Once ran the info is ported to an excel spreadsheet.

Any responses appreciated.
9   L A T E S T    R E P L I E S    (Newest First)
ajlueth Posted - 02/01/2011 : 10:03:06 AM
When you get this finalized, would you consider posting the final script or emailing it?

That Sydi server is phenomonial BTW. It does A LOT!

Thanks.
cj_berlin Posted - 01/25/2011 : 3:21:44 PM
quote:
Originally posted by Phil Marcum


The tek-tip site below seems to suggest dropping this batch of code into the script.



Not quite.

Paste the function definition (the part from the 2nd line down) at the end of the script file and then insert the following code after the If Reachable(strCompName) then line:
objXL.Cells(intRow, 16).Value = ResolveIP(strCompName)


This should be giving you an IP address in the last column.

As to the reachability issue, you can try the first TekTips script on a known-unreachable machine and see if it also hangs or if it produces a (negative) result. The Rachable function there seems to be pretty much identical.
Phil Marcum Posted - 01/25/2011 : 2:50:53 PM
No it just sits as if it's collecting data. I left and came back the next to find it still sitting at the same server.

The tek-tip site below seems to suggest dropping this batch of code into the script. I've tried this to no avail as all i get are errors.

thnks
cj_berlin Posted - 01/25/2011 : 11:40:47 AM
quote:
Originally posted by Phil Marcum


1. I can't figure out how to get it to display the IP Address of the server. I've tried unsuccessfully to get this to work.



http://www.tek-tips.com/faqs.cfm?fid=6527

quote:

2. I also can't figure out how to get it to prompt me to continue when it comes to a server it can't access. Right now it just hangs and I end up having to stop and start over.



Does it write 'Not Pingable' into the last line of the Excel sheet?
Phil Marcum Posted - 01/25/2011 : 11:01:47 AM
It's been a while but I finally came across the following script that almost does everything I'm looking for:

' *********************************************************
' * ServerInventory.vbs
' * Dependencies:
' * 1. Must run in command line.
' * 2. Must have Excel installed.
' * 3. Must have PSTools available in c:\tools\pstools.
' *
' *********************************************************

Option Explicit

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Dim logpath, objFSO, strDom, strPSPath, f1, arr1, intRow, objXL, strService1
Dim strCompName, strReachable, strOS, strSP, strMan, strMod, strDC
Dim strDHCP, strClusNode, arr2, strService, AllInstalledSoftware, strEngine
Dim objWMIService, colItems, objItem, tmpVar1, tmpVar2, tmpVar3, strWINS
Dim pos1, pos2, i, j, strRawOutput, strDNS, strSN, pstoolsPath, apps

logpath = GetPath()

'your domain below
strDom = "DC=ACME,DC=COM"
pstoolsPath = "c:\Tools\pstools"

' **Performing pre-execution validations**
strEngine = UCase(Right(WScript.FullName, 12 ))
If strEngine <> "\CSCRIPT.EXE" Then
wscript.echo "Please run this script from the command prompt" & _
"....exiting now."
wscript.quit
End If

set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(pstoolsPath) then
Wscript.echo "The folder configured in the script for PSTools " & _
"does not exist. See the comments in the top of the script " & _
"for dependency information. Exiting script..."
Wscript.quit
End If

If Not objFSO.FileExists(pstoolsPath & "\psinfo.exe") then
Wscript.echo "PSInfo.exe does not exist in the PSTools folder. " & _
"See the comments in the top of the script for dependency " & _
"information. Exiting script..."
Wscript.quit
End If

If Not objFSO.FileExists(pstoolsPath & "\psservice.exe") then
Wscript.echo "PSService.exe does not exist in the PSTools folder. " & _
"See the comments in the top of the script for dependency " & _
"information. Exiting script..."
Wscript.quit
End If

' Create Excel file
intRow = 1
err.clear
Set objXL = Wscript.CreateObject("Excel.Application")
If err.number <> 0 then
Wscript.echo "Error creating an Excel spreadsheet. Verify that " & _
"Excel is installed. Exiting script..."
Wscript.quit
End If
objXL.Visible = True
objXL.WorkBooks.Add
objXL.Sheets("Sheet1").Select()
objXL.Sheets("Sheet1").Name = "Server Inventory"
objXL.Columns(1).ColumnWidth = 15 'ServerName
objXL.Columns(2).ColumnWidth = 9 'Online
objXL.Columns(3).ColumnWidth = 20 'OS
objXL.Columns(4).ColumnWidth = 12 'SP
objXL.Columns(5).ColumnWidth = 12 'Manufacturer
objXL.Columns(6).ColumnWidth = 12 'Model
objXL.Columns(7).ColumnWidth = 12 'SerialNumber
objXL.Columns(8).ColumnWidth = 10 'DC
objXL.Columns(9).ColumnWidth = 10 'DNS
objXL.Columns(10).ColumnWidth = 10 'DHCP
objXL.Columns(11).ColumnWidth = 10 'WINS
objXL.Columns(12).ColumnWidth = 10 'ClusterNode
objXL.Columns(13).ColumnWidth = 10 'Exchange
objXL.Columns(14).ColumnWidth = 50 'Applications
objXL.Columns(15).ColumnWidth = 12 'WMI Status
objXL.Range("A1:O1").Select
objXL.Selection.Font.Bold = True
objXL.Selection.Font.Size = 8
objXL.Selection.Interior.ColorIndex = 11
objXL.Selection.Interior.Pattern = 1 'xlSolid
objXL.Selection.Font.ColorIndex = 2
objXL.Selection.WrapText = True
objXL.Columns("A:X").Select
objXL.Selection.HorizontalAlignment = 3 'xlCenter
objXL.Selection.WrapText = True

' Populate header row
objXL.Cells(intRow, 1).Value = "ServerName"
objXL.Cells(intRow, 2).Value = "Online"
objXL.Cells(intRow, 3).Value = "OS"
objXL.Cells(intRow, 4).Value = "SP"
objXL.Cells(intRow, 5).Value = "Manufacturer"
objXL.Cells(intRow, 6).Value = "Model"
objXL.Cells(intRow, 7).Value = "SerialNumber"
objXL.Cells(intRow, 8).Value = "DC"
objXL.Cells(intRow, 9).Value = "DNS"
objXL.Cells(intRow, 10).Value = "DHCP"
objXL.Cells(intRow, 11).Value = "WINS"
objXL.Cells(intRow, 12).Value = "ClusterNode"
objXL.Cells(intRow, 13).Value = "Exchange"
objXL.Cells(intRow, 14).Value = "Applications"
objXL.Cells(intRow, 15).Value = "WMI Status"
objXL.Cells(1, 1).Select

intRow = intRow + 1

arr1 = FindAllServersInDomain(strDom)

For i = 0 To UBound(arr1)
strCompName = ucase(trim(arr1(i)))
wscript.echo "Working on " & strCompName & ", number " & i + 1 & _
" in the list."
objXL.Cells(intRow, 1).Value = strCompName
'Is server ping-able?"
If Reachable(strCompName) then
objXL.Cells(intRow, 2).Value = "Online"
' Get app data and format to insert into spreadsheet
strRawOutput = ExecCmd("%comspec% /c " & pstoolsPath & _
"\psinfo -accepteula applications -s \\" & strCompName)
If strRawOutput <> "" then
If instr(1, strRawOutput, "Access is denied.", 1) = 0 then
If instr(1, strRawOutput, _
"The network path was not found.", 1) = 0 then
pos1 = Instr(1, strRawOutput, "Applications:", 1)
pos2 = Instr(1, strRawOutput, "PSInfo v", 1)
tmpVar1 = Replace(Mid(strRawOutput, pos1 + 15, _
pos2 - (pos1 + 17)), vbcrlf, ";", 1, -1, 1)
tmpVar2 = Split(tmpVar1, ";", -1, 1)
For j = 0 To UBound(tmpVar2)
If InStr(1, tmpVar2(j), _
"Security Update", 1) = 0 then
If InStr(1, tmpVar2(j), _
"Update for Windows", 1) = 0 then
If InStr(1, tmpVar2(j), _
"Hotfix", 1) = 0 then
tmpVar3 = tmpVar3 & _
tmpVar2(j) & "; "
End If
End If
End If
Next
apps = Left(tmpVar3, Len(tmpVar3) - 2)
objXL.Cells(intRow, 14).Value = apps
Else
objXL.Cells(intRow, 14).Value = _
"The network path was not found."
End If
Else
objXL.Cells(intRow, 14).Value = "Access is denied."
End If
End If
' Set up WMI Connection
On Error Resume Next
err.clear
Set objWMIService = GetObject("winmgmts:\\" & strCompName & "\root\CIMV2")
If err.number = 0 then
objXL.Cells(intRow, 15).Value = "Successfully connected to WMI"
' Get serial number
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS",,48)
For Each objItem In colItems
strSN = objItem.SerialNumber
Next
If strSN <> "" OR strSN <> NULL then
objXL.Cells(intRow, 7).Value = strSN
End If
Set colItems = Nothing
Set objItem = Nothing
' Dumping OS info
Set colItems = objWMIService.ExecQuery _
("SELECT Caption, CSDVersion FROM Win32_OperatingSystem", _
"WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
strOS = objItem.Caption
strSP = objItem.CSDVersion
Next
If strOS <> "" OR strOS <> NULL then
objXL.Cells(intRow, 3).Value = strOS
End If
If strSP <> "" OR strSP <> NULL then
objXL.Cells(intRow, 4).Value = strSP
End If
Set colItems = Nothing
Set objItem = Nothing
' Dumping Make/Model
Set colItems = objWMIService.ExecQuery _
("SELECT Manufacturer, Model FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
strMan = trim(objItem.Manufacturer)
strMod = trim(objItem.Model)
Next
If strMan <> "" OR strMan <> NULL then
objXL.Cells(intRow, 5).Value = strMan
End If
If strMod <> "" OR strMod <> NULL then
objXL.Cells(intRow, 6).Value = strMod
End If
Set colItems = Nothing
Set objItem = Nothing
' Dumping Infrastructure Roles
'Is server a DC?
strService = "kdc"
If InStr(ExecCmd(pstoolsPath & "\psservice -accepteula \\" & _
strCompName & " query " & strService), "RUNNING") <> 0 Then

objXL.Cells(intRow, 8).Value = "YES"
End If
'Is DNS installed?
If InStr(ExecCmd(pstoolsPath & "\psservice -accepteula \\" & _
strCompName & " query " & chr(34) & "DNS Server" & chr(34)), _
"RUNNING") <> 0 Then

objXL.Cells(intRow, 9).Value = "YES"
End If
'Is DHCP installed?
strService = "DHCPServer"
If InStr(ExecCmd(pstoolsPath & "\psservice -accepteula \\" & _
strCompName & " query " & strService), "RUNNING") <> 0 Then

objXL.Cells(intRow, 10).Value = "YES"
End If
'Is WINS installed?
strService = "WINS"
If InStr(ExecCmd(pstoolsPath & "\psservice -accepteula \\" & _
strCompName & " query " & strService), "RUNNING") <> 0 Then

objXL.Cells(intRow, 11).Value = "YES"
End If
'Is server a Cluster Node?
strService = "ClusSvc"
If InStr(ExecCmd(pstoolsPath & "\psservice -accepteula \\" & _
strCompName & " query " & strService), "RUNNING") <> 0 Then

objXL.Cells(intRow, 12).Value = "YES"
End If
'Is Exchange installed?
strService = "MSExchangeSA"
strService1 = "MSExchangeADTopology"
If InStr(ExecCmd(pstoolsPath & "\psservice -accepteula \\" & _
strCompName & " query " & strService), "RUNNING") <> 0 OR _
InStr(ExecCmd(pstoolsPath & "\psservice -accepteula \\" & _
strCompName & " query " & strService1), "RUNNING") <> 0 Then

objXL.Cells(intRow, 13).Value = "YES"
End If
Else
objXL.Cells(intRow, 15).Value = "Error Connecting to WMI"
End If
Else
objXL.Cells(intRow, 2).Value = "Not Ping'able"
End If
strRawOutput = ""
tmpVar1 = ""
tmpVar2 = ""
tmpVar3 = ""
strSN = ""
intRow = intRow + 1
Next

Wscript.echo "All Done!"

Function FindAllServersInDomain(dom)
' Returns an array with the names of all Windows servers in the domain specified.
' Domain name format example: "DC=AD,DC=BLS,DC=com"

Const ADS_SCOPE_SUBTREE = 2

Dim objConnection, objCommand, objRecordSet, Var1, Var2

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, Location, operatingSystem from 'LDAP://" & dom & "'" _
& " where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
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
If InStr(objRecordSet.Fields("operatingSystem").Value, "Server") <> 0 OR _
InStr(objRecordSet.Fields("operatingSystem").Value, "Windows NT") <> 0 Then
Var1 = Var1 & objRecordSet.Fields("Name").Value & ","
End If
objRecordSet.MoveNext
Loop
Var2 = Left(Var1, len(Var1) -1)
FindAllServersInDomain = Split(Var2, ",", -1, 1)
End Function

Function GetPath()
' Get script path
Dim path
path = WScript.ScriptFullName
GetPath = Left(path, InStrRev(path, "\"))
End Function

Function Reachable(comp)
Dim wmiQuery, objWMIService, objPing, objStatus

wmiQuery = "Select * From Win32_PingStatus Where Address = '" & comp & "'"

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objPing = objWMIService.ExecQuery(wmiQuery)

For Each objStatus in objPing
If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
Reachable = False 'if computer is unreacable, return false
Else
Reachable = True 'if computer is reachable, return true
End If
Next
End Function

Function ExecCmd(Command)
Dim oExec, WshShell, Line

Set WshShell = WScript.CreateObject("WScript.Shell")
Set oExec = WshShell.Exec(Command)
Line = ""
Do while oExec.Status <> 1
If not oExec.StdOut.AtEndOfStream Then
line = line & oExec.StdOut.ReadAll
End If
If not oExec.StdErr.AtEndOfStream Then
line = line & oExec.StdErr.ReadAll
End If
Loop
ExecCmd = Line
End Function

I have two problems with the script I'm hoping to get some help with:

1. I can't figure out how to get it to display the IP Address of the server. I've tried unsuccessfully to get this to work.
2. I also can't figure out how to get it to prompt me to continue when it comes to a server it can't access. Right now it just hangs and I end up having to stop and start over.

Hopefully someone can chime in as I haven't received a reply from the author of the script.
JSCLMEDAVE Posted - 07/21/2010 : 09:17:07 AM


Patrick Ogenstad is the creator of the SYDI project.
http://ogenstad.net/

Patrick is very approachable and a very nice guy. You have any questions or concerns he WILL get back with you.


Document Your Network!
SYDI is the open source project aimed to help you to document your network.

http://sydiproject.com/download/


SYDI-Server V.2.3 - Minasi Post
http://web2.minasi.com/forum/topic.asp?TOPIC_ID=32057
jaxdave Posted - 07/21/2010 : 08:37:20 AM
SYDI that Ton (Playwell) mentions is solid. One of the guys on the forum create it. Can not remember who it was off the top of my head.
wobble_wobble Posted - 07/21/2010 : 05:53:08 AM
The Microsoft MAP toolkit will do a lot of that. I haven't used it too much on linux stuff but it does appear to do some of it. The windows surveys are good.

You will need a client with Office 2007 or higher and certain other little bits, but its not bad at looking at all of that stuff.

http://technet.microsoft.com/en-us/library/bb977556.aspx
Playwell Posted - 07/21/2010 : 04:31:05 AM
The only one i know is the Sydi documentation project:
http://sydiproject.com/download/

limited support for linux though

Mark Minasi's Reader Forum © 2002-2011 Mark Minasi Go To Top Of Page
This page was generated in 0.16 seconds. Snitz Forums 2000