Hello!

I'm running into and issue which may be a result of a lack of understanding of WMI. I am trying to write a script to mine file version data from systems on the network. I have code which works but execution time seems really slow to me.

Here is the code block. I have lumped all the file queries together in a single WMI request because I hoped it would speed execution. It actually made no difference and runs the same speed as 26 individual WMI requests.

It takes about 15-19 seconds to run this code on a local system and about 40 -50 to run it on a remote LAN system.

I cannot detect a CPU or bandwidth bottleneck on either my system or the remote system. So why is it so dang slow!

Performing the same function with 26 individual \\system\c$\path\file checks takes about 3 - 5 seconds. But beats up the network. Any ideas what is wrong?

Code:
  
;;;;;;;;;;;
; Collecting file versions
;;;;;;;;;;;

$system=”.”

$objWMIService = GetObject("winmgmts:\\"+$system+"\root\cimv2")

$DataReturn = $objWMIService.ExecQuery("SELECT * FROM CIM_Datafile WHERE
Name = 'c:\\Program Files\\Internet Explorer\\IEXPLORE.EXE' OR
Name = 'c:\\winnt\\system32\\kernel32.dll' OR
Name = 'c:\\Program Files\\Microsoft Office\\Office\\Excel.exe' OR
Name = 'c:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA6\\Vbe6.dll' OR
Name = 'c:\\winnt\\system32\\Rpcss.dll' OR
Name = 'c:\\WINNT\\system32\\Msgsvc.dll' OR
Name = 'c:\\WINNT\\system32\\Shlwapi.dll' OR
Name = 'c:\\WINNT\\system32\\WKSSVC.DLL' OR
Name = 'c:\\WINNT\\system32\\Msasn1.dll' OR
Name = 'c:\\Program Files\\Common Files\\Microsoft Shared\\TextConv\\Msconv97.dll' OR
Name = 'c:\\WINNT\\system32\\inetcomm.dll' OR
Name = 'c:\\WINNT\\system32\\msjtes40.dll' OR
Name = 'c:\\WINNT\\system32\\Quartz.dll' OR
Name = 'c:\\WINNT\\system32\\cryptdlg.dll' OR
Name = 'c:\\WINNT\\system32\\Mstask.exe' OR
Name = 'c:\\WINNT\\system32\\Itss.dll' OR
Name = 'c:\\WINNT\\system32\\Shell32.dll' OR
Name = 'c:\\Program Files\\Common Files\\Microsoft Shared\\VGX\\Vgx.dll' OR
Name = 'c:\\WINNT\\system32\\Mshtml.dll' OR
Name = 'c:\\WINNT\\system32\\Hhctrl.ocx' OR
Name = 'c:\\WINNT\\system32\\Sp3res.dll' OR
Name = 'c:\\WINNT\\system32\\Ciodm.dll' OR
Name = 'c:\\Program Files\\Common Files\\Microsoft Shared\\Triedit\\Dhtmled.ocx' OR
Name = 'c:\\WINNT\\system32\\Hlink.dll' OR
Name = 'c:\\WINNT\\system32\\Wmp.dll' OR
Name = 'c:\\WINNT\\system32\\Drivers\\Tcpip.sys'",,48)

For Each $DataObject in $DataReturn
$ObjectName = $DataObject.Name
SELECT
CASE (INSTR($ObjectName, "c:\Program Files\Internet Explorer\IEXPLORE.EXE") <> 0)
$test1 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\winnt\system32\kernel32.dll") <> 0)
$test2 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\Program Files\Microsoft Office\Office\Excel.exe") <> 0)
$test3 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\Vbe6.dll") <> 0)
$test4 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\winnt\system32\Rpcss.dll") <> 0)
$test5 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Msgsvc.dll") <> 0)
$test6 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Shlwapi.dll") <> 0)
$test7 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\WKSSVC.DLL") <> 0)
$test8 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Msasn1.dll") <> 0)
$test9 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\Program Files\Common Files\Microsoft Shared\TextConv\Msconv97.dll") <> 0)
$test10 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\inetcomm.dll") <> 0)
$test11 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\msjtes40.dll") <> 0)
$test12 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Quartz.dll") <> 0)
$test13 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\cryptdlg.dll") <> 0)
$test14 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Mstask.exe") <> 0)
$test15 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Itss.dll") <> 0)
$test16 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Shell32.dll") <> 0)
$test17 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\Program Files\Common Files\Microsoft Shared\VGX\Vgx.dll") <> 0)
$test18 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Mshtml.dll") <> 0)
$test19 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Hhctrl.ocx") <> 0)
$test20 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Sp3res.dll") <> 0)
$test21 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Ciodm.dll") <> 0)
$test22 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\Program Files\Common Files\Microsoft Shared\Triedit\dhtmled.ocx") <> 0)
$test23 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Hlink.dll") <> 0)
$test24 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Wmp.dll") <> 0)
$test25 = $DataObject.Version
CASE (INSTR($ObjectName, "c:\WINNT\system32\Drivers\Tcpip.sys") <> 0)
$test26 = $DataObject.Version
CASE 1
ENDSELECT
Next

? test1
? test2
? test3
? test4
? test5
? test6
? test7
? test8
? test9
? test10
? test11
? test12
? test13
? test14
? test15
? test16
? test17
? test18
? test19
? test20
? test21
? test22
? test23
? test24
? test25
? test26