Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI Class and Properties Utility

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
0
0
US
I noticed that Microsoft took down their link for PowerShell Scriptomatic. I primarily used to use that just to identify properties in a WMI class. So I made the following to replace that utility.
Code:
#==========================================================================
#
# NAME: WMIClassInfo.ps1
#
# AUTHOR: Mark D. MacLachlan, US Foods
# DATE  : 07/11/2018 14:28:49
#
#    This code is copyright (c) 2018 US Foods.
#
#    All rights reserved.
#
#    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
#    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
#    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
#    PARTICULAR PURPOSE.
#
#    IN NO EVENT SHALL US FOODS AND/OR ITS RESPECTIVE SUPPLIERS BE
#    LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
#    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
#    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
#    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
#    OF THIS CODE OR INFORMATION.
#
# COMMENT: Displays classes and their properties
#
# MODIFICATIONS: 7/12/2018 Added code to bring form to foreground. Also 
#                added code to refresh text if class is changed.
#==========================================================================

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

#region begin GUI{ 

$Form                            = New-Object system.Windows.Forms.Form
$Form.ClientSize                 = '400,400'
$Form.text                       = "WMI Class Information"
$Form.TopMost                    = $false

$ListBox1                        = New-Object system.Windows.Forms.ListBox
$ListBox1.text                   = "listBox"
$ListBox1.width                  = 340
$ListBox1.height                 = 30
$ListBox1.location               = New-Object System.Drawing.Point(20,94)

$ClassName                       = New-Object system.Windows.Forms.ComboBox
$ClassName.text                  = "Select Class Name"
$ClassName.width                 = 319
$ClassName.height                = 41
$ClassName.location              = New-Object System.Drawing.Point(44,87)
$ClassName.Font                  = 'Microsoft Sans Serif,10'

$TextBox1                        = New-Object system.Windows.Forms.TextBox
$TextBox1.multiline              = $true
$TextBox1.width                  = 310
$TextBox1.height                 = 164
$TextBox1.location               = New-Object System.Drawing.Point(44,155)
$TextBox1.Font                   = 'Microsoft Sans Serif,10'
$TextBox1.Scrollbars             = 3

$Form.controls.AddRange(@($ClassName,$TextBox1))

#region gui events {
    $TextArray = @()
    $ClassName.Add_SelectedIndexChanged({
    $ActiveClass = $ClassName.SelectedItem
    $ActiveProperties =  get-wmiobject -class $ActiveClass -Property * | sort name |select-object [a-z]*|GM|Select Name
    $TextBox1.Text = ""
    foreach ($property in $ActiveProperties) {#.PSObject.Properties) { 
        Switch ($Property)
        {
            "@{Name=Equals}"{}
            "@{Name=GetHashCode}"{}
            "@{Name=GetType}"{}
            "@{Name=ToString}"{}
            Default{
                $property = $property -Replace "@{Name=",""
                $property = $property -Replace "}",""
                $TextBox1.AppendText($property)
                $TextBox1.AppendText("`n")
            }
        }
    }
  })
#endregion events }

#endregion GUI }


#Write your logic code here

$Classes = (Get-CimClass | Where {$_.CimClassName -match "Win32_"}).CimClassName | Sort-Object
ForEach ($Class in $Classes)
{
 $ClassName.Items.Add($Class)
}

$Form.Add_Shown({$Form.Activate()})
[void]$Form.ShowDialog()

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at
Work SMARTER not HARDER.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top