Get-WMIQualifierValue (revisited)

August 31, 2009

no comments

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
        
}
      }
   }
}


			

							  
Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*