Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading