April 14, 2005
How do I write a WMI script?
This is a nice little tool, the windows scriptomatic utility. It writes window management instrumentation scripts.
So how to exploit it, first get a text file together of the computer names you would like to investigate. Lets call it asset.txt and save it in C:\scripts.
Then let's ascertain the information, one wants to capture. I'm currently interested in the page file. Just select Win32_PageFile, and the script generator creates the following.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PageFile",,48)
For Each objItem in colItems
Wscript.Echo "AccessMask: " & objItem.AccessMask
Wscript.Echo "Archive: " & objItem.Archive
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Compressed: " & objItem.Compressed
Wscript.Echo "CompressionMethod: " & objItem.CompressionMethod
Wscript.Echo "CreationClassName: " & objItem.CreationClassName
Wscript.Echo "CreationDate: " & objItem.CreationDate
Wscript.Echo "CSCreationClassName: " & objItem.CSCreationClassName
Wscript.Echo "CSName: " & objItem.CSName
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "Drive: " & objItem.Drive
Wscript.Echo "EightDotThreeFileName: " & objItem.EightDotThreeFileName
Wscript.Echo "Encrypted: " & objItem.Encrypted
Wscript.Echo "EncryptionMethod: " & objItem.EncryptionMethod
Wscript.Echo "Extension: " & objItem.Extension
Wscript.Echo "FileName: " & objItem.FileName
Wscript.Echo "FileSize: " & objItem.FileSize
Wscript.Echo "FileType: " & objItem.FileType
Wscript.Echo "FreeSpace: " & objItem.FreeSpace
Wscript.Echo "FSCreationClassName: " & objItem.FSCreationClassName
Wscript.Echo "FSName: " & objItem.FSName
Wscript.Echo "Hidden: " & objItem.Hidden
Wscript.Echo "InitialSize: " & objItem.InitialSize
Wscript.Echo "InstallDate: " & objItem.InstallDate
Wscript.Echo "InUseCount: " & objItem.InUseCount
Wscript.Echo "LastAccessed: " & objItem.LastAccessed
Wscript.Echo "LastModified: " & objItem.LastModified
Wscript.Echo "Manufacturer: " & objItem.Manufacturer
Wscript.Echo "MaximumSize: " & objItem.MaximumSize
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Path: " & objItem.Path
Wscript.Echo "Readable: " & objItem.Readable
Wscript.Echo "Status: " & objItem.Status
Wscript.Echo "System: " & objItem.System
Wscript.Echo "Version: " & objItem.Version
Wscript.Echo "Writeable: " & objItem.Writeable
Next
So let's wrap and cut this down, so we only get what we want.
Dim oFSO, txt, strComputer
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set txt = oFSO.OpenTextFile("C:\scripts\assets.txt")
Do Until txt.AtEndOfStream
strComputer = txt.ReadLine
WScript.Echo vbCrLf & "Working with " & strComputer
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PageFile",,48)
For Each objItem in colItems
Wscript.Echo "Drive: " & objItem.Drive
Wscript.Echo "FileName: " & objItem.FileName
Wscript.Echo "FileSize: " & objItem.FileSize
Next
Loop
WScript.Echo "Completed, Life is good"
Finally passed the test
Managing in light of McGregor's Theory X and Theory Y
CMMI
Kicking HIT Leadership Up a Notch
That's just some mumbo jumbo project management BS
Outcomes - The tactic to get to the strategy
Nurse Call, VOIP, and Wi-Fi: Its just cool when things come together!
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
December 2006
November 2006
August 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
November 2005
October 2005
September 2005
August 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
January 2004
December 2003
November 2003
October 2003
Joel on Software
David Ross
Edward Prevost
Martin Fowler
The Health Care Blog
The Tales of Hoffman
The Business Word
Medical Rants
Christina's Considerations
Paul Levy
HIS Talk
Appropriate IT
Candid CIO
RSS feed




