Scripting Games, Sudden Death Challenge 5

First, some excuses!  I haven’t done much playing around with WMI so far – and was also pushed for time to get this in; it works fine but maybe a little rough around the edges!

Problem was to list properties of WMI Win32 classes with names starting from A-Z (actually from A-Y since as of today there aren’t any property names in the Win32 classes starting with Z)

  1 $w=Get-WmiObject -List|?{$_.Name -like 'Win32_*'}
  2 
  3 for ($c='A'; $c -le 'Z'; [char]$c=[int][char]$c+1) {
  4 	foreach ($name in $w) {
  5 		if ($found=$name.PSBase.properties |?{$_.name -like "$($c)*"}|Select-Object -First 1) {
  6 			"{0,-30}{1}" -f $($found.name), $($name.__CLASS)
  7 			break
  8 		}
  9 	}
 10 }

So, the script initially gets a list of all the Win32 WMI classes (in $w) and then loops through initial characters from A to Z.  For each initial character it iterates over the WMI classes checking the properties of each class for a property name beginning with the current initial letter ($name.PSBase.properties |?{$_.name -like "$($c)*"}).  When an entry is found it’s displayed and the script moves on to the next initial character.  Here’s the output on my (Vista) machine:

AdditionalDescription         Win32_JobObjectStatus
Bias                          Win32_TimeZone
ControlFlags                  Win32_SecurityDescriptor
Description                   Win32_PrivilegesStatus
ExitStatus                    Win32_ProcessStopTrace
FileName                      Win32_ModuleLoadTrace
GuidInheritedObjectType       Win32_ACE
HostingModel                  Win32_OsBaselineProvider
ImageBase                     Win32_ModuleLoadTrace
JobMemoryLimit                Win32_NamedJobObjectLimitSetting
KeepAliveInterval             Win32_NetworkAdapterConfiguration
Logfile                       Win32_NTLogEvent
MachineName                   Win32_ComputerSystemEvent
Name                          Win32_Trustee
Operation                     Win32_PrivilegesStatus
ParameterInfo                 Win32_PrivilegesStatus
Quarter                       Win32_CurrentTime
RecordNumber                  Win32_NTLogEvent
StatusCode                    Win32_PrivilegesStatus
TIME_CREATED                  Win32_Trustee
UserStackBase                 Win32_ThreadStartTrace
Version                       Win32_OsBaselineProvider
Win32ErrorCode                Win32_JobObjectStatus
XOffCharacter                 Win32_SerialPortConfiguration
YResolution                   Win32_PrinterConfiguration
Advertisements

1 thought on “Scripting Games, Sudden Death Challenge 5”

  1. Hey, Chris
    Small comment :
     
    >> (actually from A-Y since as of today there aren\’t any property names in the Win32 classes starting with Z)
     
    On your machine that is ;-) I still needed 0..24
     
    PS I:\\Users\\Administrator> (gwmi -list |% {([wmiclass]$_.name).properties} |>>   where {$_.origin -like "win32_*"} |>>     select name,origin | sort -unique {$_.name[0]})[25]>>
    Name                                                        Origin—-                                                        ——ZoneTransferRequestReceived                                 Win32_PerfRawData_DNS_DNS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s