3

I am new to PowerShell and ran into a bit of a roadblock. I am trying to pull program name and version information from multiple servers.

I have a list of the program names in a $list variable, but the program names also contain the version numbers in them. I am just storing the names of the programs in the list variable without the version numbers.

I am trying to figure out a way to use both the -like and -in parameters with the Where-Object cmdlet in order to match the full program entry name (e.g. AdToUserCacheSync 1.10.1.10) with my entry in the $list variable (e.g. AdToUserCacheSync).

How can I do this?

$list = Get-Content "\\server\c$\temp\list.txt"
$storeTestServers = Get-Content "\\server\c$\temp\testStores.txt"

foreach ($server in $storeTestServers) {

    Get-WmiObject -Class Win32_Product -ComputerName $server |
    Select-Object -Property PSComputerName, Name, Version |
    Where-Object {$_.pscomputername -like "940*" -and $_.name -like -in "*$list*"}
}

2 Answers 2

6

The Where-Object FilterScript block is just a scriptblock that returns $true, $false or nothing - you can do all kinds of crazy things inside it, including looping over an array to see if there is a wildcard match in one of the entries:

Where-Object {
    $ProductName = $_.Name
    $_.pscomputername -like "940*" -and (
        $list | ForEach-Object {
            if($ProductName -like "*$_*"){ return $true }
        }
    )
}
Sign up to request clarification or add additional context in comments.

Comments

1

I found the Adobe version by PowerShell:

Get-WmiObject -Class Win32_Product -ComputerName 127.0.0.1 |
Select-Object -Property PSComputerName, Name, Version |
Where-Object {$_.Name -like "Adobe*"} | Out-File Adobe_Log.log

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.