/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" MSH Orphan share remover Tool "," MSH Welcome screen "," Read the raw Monad XML helpfiles "," MSH prompt-User function with Help "," Monad IRC Bot "," Getting performanceMonitor info from Monad "," Monad -and More bytes with -band = shorter script "," Tip from Monad "," MSH AD querying with .NET 2.0 framework "," get AD user allowed Logonhours from MSH "," ")

Tuesday, December 20, 2005

 


Saving a WMI instance to a XML-file from MSH



if you want to save all the information of the win32_operatingsystem WMI class to an XML file,it's as easy as this in Monad :
([xml](get-WMIObject win32_operatingsystem).GetText("WmiDtd20")).save("c:\os.xml")

You can open this file in IE to see how it looks, but as you can see below and in the entry "Read the raw Monad XML helpfiles " Monad has also some nice way's to walk the XML

Some more info and examples :
# get methodinfo

MSH>(get-WMIObject win32_operatingsystem).GetText


MemberType : Method
OverloadDefinitions : {System.String GetText(TextFormat format)}
TypeOfValue : System.Management.Automation.MshMethod
Value : System.String GetText(TextFormat format)
Name : GetText
IsInstance : True

# get the full Classname

MSH>(get-WMIObject win32_operatingsystem).GetText("foo")
Cannot convert argument "0", with value: "lol", for "GetText" to type "System.Management.TextFormat".
At line:1 char:46

# get the formats

[enum]::getnames([System.Management.TextFormat])
Mof
CimDtd20
WmiDtd20

# get te MOF text

(get-WMIObject win32_operatingsystem).GetText("Mof")

# get the XML text.

MSH>(get-WMIObject win32_operatingsystem).GetText("WmiDtd20")
<INSTANCE CLASSNAME="Win32_OperatingSystem"><QUALIFIER NAME="dynamic" PROPAGATED="true" TYPE="boolean" TOSUBCLASS="false" TOINSTANCE="true"
><VALUE>TRUE</VALUE></QUALIFIER><QUALIFIER NAME="Locale" PROPAGATED="true" TYPE="sint32" TOSUBCLASS="false" TOINSTANCE="true"><VALUE>1033</
...
....

# get the instance to an XML document

[xml]$os = (get-WMIObject win32_operatingsystem).GetText("WmiDtd20")

MSH>$os

INSTANCE
--------
INSTANCE


MSH>$os.INSTANCE

CLASSNAME QUALIFIER PROPERTY PROPERTY.ARRAY
--------- --------- -------- --------------
Win32_OperatingSystem {dynamic, Locale, provider, UUID} {__PATH, __NAMESPACE, __SERVER,... PROPERTY.ARRAY


MSH>$os.INSTANCE.property

NAME CLASSORIGIN TYPE VALUE
---- ----------- ---- -----
__PATH ___SYSTEM string \\puter\root\cimv2:Win32_O...
__NAMESPACE ___SYSTEM string root\cimv2
...
...

# a single property

MSH>$os.INSTANCE.property[10]


NAME : BuildNumber
CLASSORIGIN : Win32_OperatingSystem
TYPE : string
QUALIFIER : QUALIFIER
VALUE : 2600


# back to XML

MSH>,$os.INSTANCE.property[10].get_OuterXml()
<PROPERTY NAME="BuildNumber" CLASSORIGIN="Win32_OperatingSystem" TYPE="string"><QUALIFIER NAME="CIMTYPE" PROPAGATED="true" TYPE="string" TO
INSTANCE="true"><VALUE>string</VALUE></QUALIFIER><VALUE>2600</VALUE></PROPERTY>

# count properties

MSH>$os.INSTANCE.property.count
70

# list propertynames

MSH>$os.INSTANCE.property | foreach {$_.name}
__PATH
__NAMESPACE
__SERVER
__PROPERTY_COUNT
__RELPATH
__DYNASTY
__SUPERCLASS
__CLASS
__GENUS
BootDevice
BuildNumber
BuildType
Caption
CodeSet
CountryCode
....

# Save The XML to a XML file

$os.save("c:\os.xml")




you might think that you can do that from the WMI object also and more easy maybe, but think about it that we are working with a file, you can send it to someone and they can do the same querying with it, or apply formatting.

Also you can process this XML to create a webpage or something, using styles and Xpath.

I thinking about a entry about searching XML from MSH using Xpath etc, and firing up a treeview from MSH but my XML needs a freshup first.

but you can see there are a lot more of uses of having this info in XML format.

gr /\/\o\/\/


Comments: Post a Comment

Links to this post:

Create a Link



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?