<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Edwin M Sarmiento&gt;using WMI and VBScript to audit your workstations &#8211; Edwin M Sarmiento</title>
	<atom:link href="https://www.edwinmsarmiento.com/using-wmi-and-vbscript-to-audit-your-workstations/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.edwinmsarmiento.com</link>
	<description>Intentional Excellence</description>
	<lastBuildDate>Mon, 13 Apr 2026 21:00:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">84283043</site>		<item>
		<title>&gt;using WMI and VBScript to audit your workstations</title>
		<link>https://www.edwinmsarmiento.com/using-wmi-and-vbscript-to-audit-your-workstations/</link>
		<comments>https://www.edwinmsarmiento.com/using-wmi-and-vbscript-to-audit-your-workstations/#comments</comments>
		<pubDate>Tue, 30 Oct 2007 14:08:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2007/10/30/using-wmi-and-vbscript-to-audit-your-workstations</guid>

				<description><![CDATA[&#62; Auditing hardware and software for all machines in your domain can be time consuming. For small organizations, it may be a bit manageable provided that you already have a checklist of items that you need to look at for auditing purposes. CPU, disk, RAM, OS, service pack versions, etc. are just a few of [&#8230;]]]></description>
					<content:encoded><![CDATA[<p>&gt;</p>
<p><span style="font-family:arial;font-size:100%;">Auditing hardware and software for all machines in your domain can be time consuming. For small organizations, it may be a bit manageable provided that you already have a checklist of items that you need to look at for auditing purposes. CPU, disk, RAM, OS, service pack versions, etc. are just a few of those things you would like to take into account when doing auditing and inventory. For larger organizations, this could be a big challenge. Since I work for an organization that provides IT services for clients, we are required to maintain server information for auditing and inventory purposes. Imagine me doing this for almost 200+ Windows 2000 and Windows 2003 servers in multiple domains, not to mention Windows XP workstations. Being a lazy guy as I am, I wrote a script to simply automate this task. It uses VBScript and WMI to retrieve hardware, software and operating system information from computers in the domain. This requires administrative rights on the machine where this script is executed. It generates a text file (with filename <em><strong><span style="color:#3366ff;">servername_yyyymmdd_Audit.txt</span></strong></em>) which contains the information retrieved by the script. This is my list of information, you can always generate a lot more information by referring to the </span><a href="http://msdn.microsoft.com/library/en-us/wmisdk/wmi/wmi_start_page.asp?frame=true"><u><span style="font-family:arial;font-size:100%;color:#800080;">WMI SDK</span></u></a><span style="font-family:arial;font-size:100%;">. Simply replace the value in the strComputer variable to the name/IP address of the computer you wish to audit</span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>On Error Resume Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>Const HKEY_LOCAL_MACHINE = &amp;H80000002</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;change this value to the IP address or hostname of the machine you need to audit<br />strIPvalue = &#8220;.&#8221;</p>
<p>CALL GenerateReport(strIPvalue)</p>
<p>WScript.Echo &#8220;Inventory Complete &#8220;</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong></strong></em></span><br /><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;=================================================================================<br />&#8216;SUB-ROUTINE GenerateReport<br />SUB GenerateReport(strIPvalue)</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;Script to change a filename using timestamps<br />strPath = &#8220;C:&#8221;   &#8216;Change the path to appropriate value<br />strMonth = DatePart(&#8220;m&#8221;, Now())<br />strDay = DatePart(&#8220;d&#8221;,Now())</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>if Len(strMonth)=1 then<br /> strMonth = &#8220;0&#8221; &amp; strMonth<br />else<br /> strMonth = strMonth<br />end if</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>if Len(strDay)=1 then<br /> strDay = &#8220;0&#8221; &amp; strDay<br />else<br /> strDay = strDay<br />end if</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>strFileName = DatePart(&#8220;yyyy&#8221;,Now()) &amp; strMonth &amp; strDay<br />strFileName = Replace(strFileName,&#8221;:&#8221;,&#8221;&#8221;)<br />&#8216;=================================================================================</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;Variable Declarations<br />Const ForAppending = 8</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;===============================================================================<br />&#8216;Main Body<br />On Error Resume Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;CompName<br />strComputer = strIPvalue<br />Set objWMIService = GetObject(&#8220;winmgmts:&#8221; _<br />     &amp; &#8220;{impersonationLevel=impersonate}!\&#8221; &amp; strComputer &amp; &#8220;rootcimv2&#8221;)<br />&#8216;===============================================================================</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;================================================================<br />&#8216;For INTERNET EXPLORER<br />Dim strIE<br />Set objWMIService2 = GetObject(&#8220;winmgmts:{impersonationLevel=impersonate}!\&#8221; &amp; strComputer &amp; &#8220;rootcimv2ApplicationsMicrosoftIE&#8221;)<br />Set colIESettings = objWMIService2.ExecQuery(&#8220;Select * from MicrosoftIE_Summary&#8221;)<br />For Each strIESetting in colIESettings<br />    strIE= &#8221;          INTERNET EXPLORER: &#8221; &amp; strIESetting.Name &amp; &#8221; v&#8221; &amp; strIESetting.Version &amp; VBCRLF<br />Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;Get Operation System &amp; Processor Information<br />Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_Processor&#8221;,,48)<br />For Each objItem in colItems<br />     CompName = objItem.SystemName<br />Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>Set objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br />if objFSO.FileExists(strPath &amp; CompName &amp; &#8220;_&#8221; &amp; strFileName &amp; &#8220;_Audit.txt&#8221;) then<br /> WScript.Quit<br />end if</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;Set the file location to collect the data<br />Set objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br />Set objTextFile = objFSO.OpenTextFile(strPath &amp; CompName &amp; &#8220;_&#8221; &amp; strFileName &amp; &#8220;_Audit.txt&#8221;, ForAppending, True)</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8221;==============================================================<br />&#8216;Print HEADER<br />objTextFile.Write &#8220;================================================================&#8221; &amp; VBCRLF &amp; VBCRLF<br />objTextFile.Write &#8221;                     SERVER RESOURCE AUDIT REPORT               &#8221; &amp; VBCRLF<br />objTextFile.Write &#8221;                     DATE:  &#8221; &amp;    FormatDateTime(Now(),1)   &amp; &#8221;                   &#8221; &amp; VBCRLF<br />objTextFile.Write &#8221;                     TIME:  &#8221; &amp;    FormatDateTime(Now(),3)   &amp; &#8221;                   &#8221; &amp; VBCRLF &amp; VBCRLF<br />objTextFile.Write &#8220;================================================================&#8221; &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>objTextFile.Write &#8220;COMPUTER&#8221; &amp; VBCRLF<br />&#8216;==============================================================<br />&#8216;Get OPERATING SYSTEM &amp; Processor Information<br />     objTextFile.Write &#8221;          COMPUTER NAME: &#8221; &amp;  CompName &amp; VBCRLF</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_Processor&#8221;,,48)<br />For Each objItem in colItems<br />     objTextFile.Write &#8221;          PROCESSOR: &#8221; &amp;  objItem.Name &amp; VBCRLF<br />Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>Set colProcs = objWMIService.ExecQuery(&#8220;Select * from Win32_ComputerSystem&#8221;)</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>For Each objItem in colProcs<br /> objTextFile.Write &#8221;          NUMBER OF PROCESSORS: &#8221; &amp; objItem.NumberOfProcessors &amp; VBCRLF &amp; VBCRLF<br />Next<br /> </strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;================================================================<br />&#8216;Get DOMAIN NAME information<br />Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_NTDomain&#8221;)</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>For Each objItem in colItems<br />    objTextFile.Write &#8221;          DOMAIN NAME: &#8221; &amp;  objItem.DomainName &amp; VBCRLF<br />Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;================================================================<br />&#8216;Get OS Information<br />Set colSettings = objWMIService.ExecQuery(&#8220;SELECT * FROM Win32_OperatingSystem&#8221;)<br />For Each objOperatingSystem in colSettings<br /> objTextFile.Write &#8221;          OPERATING SYSTEM: &#8221; &amp; objOperatingSystem.Name &amp; VBCRLF<br /> objTextFile.Write &#8221;          VERSION: &#8221; &amp; objOperatingSystem.Version &amp; VBCRLF<br /> objTextFile.Write &#8221;          SERVICE PACK: &#8221; &amp; objOperatingSystem.ServicePackMajorVersion &amp; &#8220;.&#8221; &amp; objOperatingSystem.ServicePackMinorVersion &amp; VBCRLF<br />Next<br /> objTextFile.Write strIE &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong></strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong></strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>objTextFile.Write &#8220;MOTHERBOARD&#8221; &amp; VBCRLF </strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;===============================================================<br />&#8216;Get Main Board Information<br />Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_BaseBoard&#8221;,,48)<br />For Each objItem in colItems<br />     objTextFile.Write &#8221;          MAINBOARD MANUFACTURER: &#8221;  &amp; objItem.Manufacturer &amp; VBCRLF<br />     objTextFile.Write &#8221;          MAINBOARD PRODUCT: &#8221; &amp;  objItem.Product &amp; VBCRLF<br />Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong></strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;================================================================<br />&#8216;Get BIOS Information<br />Set colItems = objWMIService.ExecQuery(&#8220;Select * from Win32_BIOS&#8221;,,48)<br />For Each objItem in colItems<br />     objTextFile.Write &#8221;          BIOS MANUFACTURER: &#8221; &amp; objItem.Manufacturer &amp; VBCRLF<br />     objTextFile.Write &#8221;          BIOS VERSION: &#8221; &amp;  objItem.Version &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF<br />Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>objTextFile.Write &#8220;MEMORY&#8221; &amp; VBCRLF </strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;===================================================================<br />&#8216;Get Total Physical memory<br />Set colSettings = objWMIService.ExecQuery(&#8220;Select * from Win32_ComputerSystem&#8221;)<br />For Each objComputer in colSettings<br />     objTextFile.Write &#8221;          TOTAL PHYSICAL RAM: &#8221; &amp; Round((objComputer.TotalPhysicalMemory/1000000000),4) &amp; &#8221; GB&#8221; &amp; VBCRLF<br />Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>objTextFile.Write &#8221; &#8221; &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF &amp; &#8220;PARTITIONS&#8221; &amp; VBCRLF </strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;===================================================================<br />&#8216;Get Logical Disk Size and Partition Information<br />Set colDisks = objWMIService.ExecQuery(&#8220;Select * from Win32_LogicalDisk Where DriveType = 3&#8221;)<br />For Each objDisk in colDisks<br />    intFreeSpace = objDisk.FreeSpace<br />    intTotalSpace = objDisk.Size<br />    pctFreeSpace = intFreeSpace / intTotalSpace<br />    objTextFile.Write &#8221;          DISK &#8221; &amp; objDisk.DeviceID &amp; &#8221; (&#8221; &amp; objDisk.FileSystem &amp; &#8220;) &#8221; &amp;  Round((objDisk.Size/1000000000),4) &amp; &#8221; GB (&#8220;&amp; Round((intFreeSpace/1000000000)*1.024,4) &amp; &#8221; GB Free Space)&#8221; &amp; VBCRLF<br />Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>objTextFile.Write &#8221; &#8221; &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF &amp; &#8220;NETWORK&#8221; &amp; VBCRLF </strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;====================================================================<br />&#8216;Get NETWORK ADAPTERS information<br />Dim strIP, strSubnet, strDescription</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>Set colNicConfigs = objWMIService.ExecQuery(&#8220;SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True&#8221;)</p>
<p>For Each objNicConfig In colNicConfigs<br />       &#8216;Assign description values to variable<br />       strDescription=objNicConfig.Description</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>       For Each strIPAddress In objNicConfig.IPAddress<br /> &#8216;Assign IP Address to variable<br /> strIP=strIPAddress </strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>   For Each strIPSubnet In objNicConfig.IPSubnet<br />      &#8216;Assign Subnet to variable<br />      strSubnet = strIPSubnet<br />   Next</p>
<p> objTextFile.Write &#8221;          NETWORK ADAPTER: &#8221; &amp; strDescription &amp; VBCRLF<br />  objTextFile.Write &#8221;          IP ADDRESS: &#8221; &amp; strIP &amp; VBCRLF<br />    objTextFile.Write &#8221;          SUBNET MASK: &#8221; &amp; strSubnet &amp; VBCRLF &amp; VBCRLF</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>       Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>Set colNicConfigs =NOTHING</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;============================================================</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong> objTextFile.Write &#8221; &#8221; &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF &amp; VBCRLF &amp; &#8220;APPLICATION&#8221; &amp; VBCRLF </strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong> Set objReg = GetObject(&#8220;winmgmts:{impersonationLevel=impersonate}!\&#8221; &amp; strComputer &amp; &#8220;rootdefault:StdRegProv&#8221;)</p>
<p> strKeyPath = &#8220;SOFTWAREMicrosoftWindowsCurrentVersionUninstall&#8221;<br /> objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong> For Each subkey In arrSubKeys<br />  strSubKeyPath = strKeyPath &amp; &#8220;&#8221; &amp; subkey</p>
<p>  strString = &#8220;DisplayName&#8221;<br />  objReg.GetStringValue HKEY_LOCAL_MACHINE, strSubKeyPath, strString, strDisplayName</p>
<p>  strString = &#8220;DisplayVersion&#8221;<br />  objReg.GetStringValue HKEY_LOCAL_MACHINE, strSubKeyPath, strString, strDisplayVersion</p>
<p>  strDisplayName=Trim(strDisplayName)<br />  strDisplayVersion=Trim(strDisplayVersion)<br />  If strDisplayName &lt;&gt; &#8220;&#8221; And strDisplayVersion &lt;&gt; &#8220;&#8221; Then<br />   objTextFile.Write &#8221;          &#8221; &amp; strDisplayName &amp; &#8221; &#8221; &amp; strDisplayVersion &amp; VBCRLF<br />  End If<br /> Next</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;===========================================</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong></strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;Close text file after writing logs</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>objTextFile.Write VbCrLf<br />objTextFile.Close</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;Clean Up</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>SET colIESettings=NOTHING<br />SET colItems=NOTHING<br />SET colSettings=NOTHING<br />SET colDisks=NOTHING<br />SET AdapterSet=NOTHING<br />SET objWMIService=NOTHING<br />SET objWMIService2=NOTHING<br />SET objFSO=NOTHING<br />SET objTextFile=NOTHING</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>&#8216;===================================================================<br />END SUB</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong></strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong>Function HostOnline(strComputername)</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong> Set sTempFolder = objFso.GetSpecialFolder(TEMPFOLDER)<br /> sTempFile = objFso.GetTempName<br /> sTempFile = sTempFolder &amp; &#8220;&#8221; &amp; sTempFile</strong></em></span></p>
<p><span style="font-size:85%;color:#0070c0;"><em><strong> objShell.Run &#8220;cmd /c ping -n 2 -l 8 &#8221; &amp; strComputername &amp; &#8220;&gt;&#8221; &amp; sTempFile,0,True</p>
<p> Set oFile = objFso.GetFile(sTempFile)<br /> set oTS = oFile.OpenAsTextStream(ForReading)<br /> do while oTS.AtEndOfStream &lt;&gt; True<br />  sReturn = oTS.ReadLine<br />  if instr(sReturn, &#8220;Reply&#8221;)&gt;0 then<br />   HostOnline = True<br />   Exit Do<br />  End If<br /> Loop</p>
<p> ots.Close<br /> oFile.delete<br />End Function</strong></em></span></p>
<p><em><span style="font-size:85%;color:#0000ff;"></span></em></p>
<p><span style="font-size:100%;"><span style="font-family:arial;">If you are dealing with an organization with more than 50 computers and servers, it would still be tiresome to manually execute this script on each machine/server. A better way to do it is to have an Excel spreadsheet that contains the machine names/IP addresses of all the computers in your domain. read through the list and generate the text files based on that list. In my next blog entry, I will start with reading an Excel spreadsheet using VBScript and continue on to incorporate this script.</span> </span></p>
<div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/92377218009570869-8036750028745293687?l=bassplayerdoc.blogspot.com' alt='' /></div>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/using-wmi-and-vbscript-to-audit-your-workstations/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">46</post-id>	</item>
	</channel>
</rss>