/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Create System Variable From MSH (Part2) "," Create System Variable From MSH "," Setting the Path / system variables from MSH "," Obfuscated Monad Script "," Get Binary SID in MSH (Share Security Update) "," Replace Security on existing share using MSH "," Einstein "," Runas with loading Profile script in MSH "," do the MSH - CMD- MSH loop. & RunAs in MSH "," list processes of remote computer from MSH "," ")

Friday, November 04, 2005


Wmi-Help Part 1

This is the first part of a serie about making a WMI help system in MSH.

this helpsystem will use the helpdescriptions that are already in WMI,
as you will see they are a bit hidden, and not always as verbose as we would want,but the are a good start, and as the are stored in the MOF files we can even change them and make your own ones (as this is way out of scope, I will not cover this here ;-))

the first part is about getting the classes and there Help (description)
this script will get all WMI classes and descriptions and put them into a HashTable for easy reference.

First interesting part is the #set Options Part

$opt.EnumerateDeep = $true

will instruct the managementclass (MC)to do a Deep enumeration, otherwise we will not get all the WMI classes back, since there not al on the same level.

the second one,

$opt.UseAmendedQualifiers = $true

is very important, because it will instruct the MC to get Amended Qualifiers also, because description is one of them .(Descriptions are stored in the MOF files, and must be retrieved)

Next are 2 booleans

$bWin32 = $true
$bPerf = $true

they will filter out the non win32_ classes and the Performancecounter classes, because most of the Time we will not want them cluttering the list, I already implemented them for making it into a switch later, so that if you need them you can get them.

next is the loop that will put hem all in a array list.

afer you run this script you can use it like this

MSH G:\Monad> $classes

Key Value
--- -----
win32_quotasetting The Win32_QuotaSetting class contains setting information for disk quotas on a volume.
win32_cdromdrive The Win32_CDROMDrive class represents a CD-ROM drive on a Win32_ComputerSystem.
win32_process The Win32_Process class represents a sequence of events on a Win32 system. Any sequence consisting of the...


or like this :

MSH G:\Monad> $classes.win32_share
The Win32_Share class represents a shared resource on a Win32 system. This may be a disk drive, printer, interprocess communication, or oth
er shareable device.
Example: C:\PUBLIC.

In the next part we will dive deeper into the Class and get the Properties and Methods and again the descriptions (Yes the Methods ans Properties contain them to0) from a Single WMI Class.

the plans for the 3th part, are getting the InputParameters of Methods (and here also we have helpdescriptions again).

and then in the last part put it al together and go for the Execution ;-)

gr /\/\o\/\/

If you use it from file / function don't forget to "Dot Source" it to get access to the HashArray.

. .\GetWmiClasses.MSH

otherwise the HashArray is out of scope (will be gone as the script ends).

# GetWmiClasses.MSH
# Gets all WMI classes and the descriptions into a HashTable
# /\/\o\/\/ 2005

$MS = new-object system.management.ManagementScope
$MC = new-object system.management.ManagementClass($MS,$NULL,$NULL)

# Set Options
$opt = new-object system.management.EnumerationOptions
$opt.EnumerateDeep = $True
$opt.UseAmendedQualifiers = $true

$classes = @{}
#new-object system.collections.arraylist
$I = 0

# Booleans to filter non win32_ classes and perfmon Classes
$bWin32 = $true
$bPerf = $true

write-host "Getting Classes"
$MC.GetSubclasses($opt) | foreach {
  if ( $bWin32 -eq $true -and $bPerf -eq $true) {
    $Name = $_.get_ClassPath().ClassName.ToLower()
    If ( $Name.StartsWith("win32") -and !$Name.StartsWith("win32_perf")) {
  ElseIf ( $bWin32 -eq $true ) {
    If ( $_.ClassName.ToLower().StartsWith("win32")) {
  Else {
  #Idicate whe are busy by outputting a dot every 10 classes
  If ($Classes.Count - $i -ge 10) { $i = $classes.count ; write-host -no . }
write-host '`nFinished use $classes[.className] to get descriptions'

Comments: Post a Comment

Links to this post:

Create a Link

<< Home


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.
Web mow001.blogspot.com

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