Search code examples
powershellget-wmiobject

Powershell: Trying to return specific values from a WMIObject query


I am trying to create a PowerShell script that will pull details about specific software on my computer. To accomplish this, I am trying to use Get-WMIObject. I am able to pull the list of all software on my computer using. Get-WmiObject -Class Win32_Product. I would like to manipulate this to return only specific software. I created a variable with the list of software and added it to the script. Now I am getting an error that name "is not recognized as the name of a cmdlet, function, script file, or operable program". I same name instead of what is in my code because I have tried many variations (name, $_.Name, WmiObject.Name, .Name). All return a similar error. I checked Get-Member to verify, and name is a property of the objects I should be returning. I have also tried parentheses starting with where-object and also wrapping the entire script in parentheses.

$SoftWare = @(
    'Office 16 Click-to-Run Licensing Component',
    'Adobe Acrobat',
    'Google Chrome',
    'Local Administrator Password Solution',
)


Get-WmiObject -Class Win32_Product | Where-Object {$._name -EQ $SoftWare}

Solution

  • Ok. You are using the wrong comparison operator. YOu would use "-eq" when comparing one value to another single value. You are comparing one value to an array of values, so try this:

    Get-WmiObject -Class Win32_Product | Where-Object {$_.name -in $SoftWare}
    

    -In will determine if the a single value is contained within an array of values. Oh, "Where-object" query was incorrect to. Move the period over one.