DCSIMG
Get-WMIQualifierValue (revisited) - Shay Levy

Shay Levy

If you repeat it, PowerShell it!

Get-WMIQualifierValue (revisited)

An updated version of my Get-WMIQualifierValue function. With this version you can query remote computers, specify the NameSpace of the class and also specify a property name to get just its values instead of all properties.

Sample Usage:

Get-WMIQualifierValue -Class Win32_LogicalDisk -ComputerName computer1 –Property StatusInfo

 

function Get-WMIQualifierValue
{

   param(
     
[string]$Class=$(Throw Parameter ‘Class’ cannot be empty),
      [string]$ComputerName=".",
      [string]$NameSpace="ROOT\cimv2",
      [
string]$Property="*"
  
)

   if($PSVersionTable)
   {
    
#PowerShell v2 detected 
    
$wmi = Get-WmiObject meta_class -Filter "__Class = '$class'" -Amended  ` 
   
-ComputerName $ComputerName -Namespace $NameSpace
   }
 
  
else
  
{
    
#PowerShell v1 detected
   
 $wmi=[wmiclass]"\\$ComputerName\$($NameSpace):$class" 
    
$wmi.psbase.options.useAmendedQualifiers=$true 
   }

   foreach ($p in $wmi.psbase.properties)
   {
     
$names = $p.qualifiers | ForEach-Object {$_.name}

      if($names -contains "values" -AND $names -contains "valuemap")
      {
        
$pLen = "-" * $p.name.length
        
$value = $p.qualifiers["Values"].value
        
$meaning = $p.qualifiers["ValueMap"].value
        
$map = $value | Select-Object Value,@{Name="Meaning";Expression={$_}}
        
1..$map.length | ForEach-Object { $map[$_-1].value=$meaning[$_-1] }
        
$map = $map | Add-Member NoteProperty Name $p.name –PassThru

         if($Property -eq "*")
         {
          
Write-Host ("`n$pLen`n"+$p.name+"`n$pLen")
          
$map | Select-Object Value,Meaning | Format-TableAutoSize 
         }

         if($p.name -eq $Property)
         {
          
Write-Host ("`n$pLen`n"+$p.name+"`n$pLen")
          
$map | Where-Object {$_.name -eq $Property } | Select-Object Value,Meaning | Format-Table –AutoSize
         
 break
        
}
      }
   }
}


       

            
    

Comments

Twitter Trackbacks for Get-WMIQualifierValue (revisited) - Shay Levy [microsoft.co.il] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Get-WMIQualifierValue (revisited) - Shay Levy         [microsoft.co.il]        on Topsy.com

# August 31, 2009 4:13 PM

Baby name meaning and origin for P said:

Pingback from  Baby name meaning and origin for P

# October 22, 2009 5:54 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: