Get-WMIInfo.ps1

# =====================================================================================
# 
# Microsoft PowerShell Source File -- Created with SAPIEN Technologies PrimalScript 2009
# 
# NAME: Get-WMIInfo.ps1
# 
# AUTHOR: Jeffery Hicks , SAPIEN Technologies
# DATE  : 6/11/2009
# 
# COMMENT: Discover information about a given WMI class such as
# a help description, its methods and properties.
#
# The script will write a custom object with WMI information
# to the pipeline, or you can use -report to display an expanded 
# view of the class' methods and properties.

# This script cannot use alternate credentials to connect to remote
# computers. You must run it under an account that has admin
# privileges on the remote computer.

# DISCLAIMER AND WARNING:
# 	THIS CODE AND INFORMATION ARE 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.
#   TEST THOROUGHLY IN A NON-PRODUCTION ENVIRONMENT. IF YOU DON'T KNOW WHAT THIS
#   SCRIPT WILL DO...DO NOT RUN IT!
# 
# ====================================================================================

Param([string]$Class="Win32_OperatingSystem",
      [string]$computername=$env:computername,
      [string]$namespace="ROOT\CIMV2",
      [switch]$report
     )

#turn off the error pipeline
$errorActionPreference="SilentlyContinue"     

Trap [System.Management.Automation.PSInvalidCastException] {
#this traps errors attempting to retrieve the WMI class
    Write-Warning ("There was an error trying to get the {0}`
         class from the {1} namespace on {2}.` 
         {3}" -f $Class.ToUpper(),$namespace.ToUpper(),`
         $computername.ToUpper(),$($_.exception.message))
    Return
}

Trap {
#this will trap all other errors and let the script continue
  Continue
}

[WMICLASS]$wmi="\\{0}\{1}:{2}" -f $computername,$namespace,$Class

#set object to use amended qualifiers
$wmi.psbase.options.UseAmendedQualifiers=$true
 
#define an array for property names
[email protected]()
$wmi.psbase.properties | foreach {
    #add each property name to $properties
    $properties+=$_.name
  }

#define an array for method names
[email protected]()
$wmi.psbase.methods | foreach {
    #add each method name to $methods
    $methods+=$_.name
  }
#if no methods found set a new value
if ($methods.count -eq 0) {
    $methods="None"
}
  
#get class description
$description=$wmi.psbase.GetQualifierValue("description")

#if no description then define a new value
if (!$description) {
  $description= "No Description Found"
}

#create an empty custom object
$obj=New-Object PSObject
  
#assign properties
$obj | Add-Member -MemberType Noteproperty -name "Computername"
   -value $computername.ToUpper()
$obj | Add-Member -MemberType Noteproperty -name "Path" -value $wmi.path.path.ToUpper()
$obj | Add-Member -MemberType Noteproperty -name "Namespace" -value $namespace.ToUpper()
$obj | Add-Member -MemberType Noteproperty -name "WMIClass" -value $class.ToUpper()
$obj | Add-Member -MemberType Noteproperty -name "Description" -value $description
$obj | Add-Member -MemberType Noteproperty -name "Properties" -value $properties
$obj | Add-Member -MemberType Noteproperty -name "Methods" -value $methods

#if -report was specified display a formatted report
if ($report) {
    $obj | Format-List Path,WMIClass,Description,`
    @{label="Properties";Expression={$_.properties | Out-String}},`
    @{label="Methods";Expression={$_.Methods | Out-String}} 
} 
else {
    #otherwise, just write the object
    write $obj
}

#end of script

Featured

  • Microsoft Hires Movial To Build Android OS for Microsoft Devices

    Microsoft has hired the Romanian operations of software engineering and design services company Movial to develop an Android-based operating system solution for the Microsoft Devices business segment.

  • Microsoft Ending Workflows for SharePoint 2010 Online Next Month

    Microsoft on Monday gave notice that it will be ending support this year for the "workflows" component of SharePoint 2010 Online, as well as deprecating that component for SharePoint 2013 Online.

  • Why Windows Phone Is Dead, But Not Completely Gone

    Don't call it a comeback (because that's not likely). But as Brien explains, there are three ways that today's smartphone market leaves the door open for Microsoft to bring Windows back to smartphones.

  • Feature Update Deferral Mix-Up in Windows 10 Version 2004 Further Explained

    Microsoft last week described the confusion it is attempting to avoid by removing the client graphical user interface (GUI)-based controls to defer Windows 10 feature updates, starting with version 2004.

comments powered by Disqus

Office 365 Watch

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.