1

These cmdlets work:

Get-WmiObject Win32_PNPSignedDriver -Filter "DriverProviderName <> NULL"
Get-WmiObject Win32_PNPSignedDriver -Filter "DriverProviderName <> 'Microsoft'"

I can't seem to combine them with a OR statement & I don't know why: Get-WmiObject Win32_PNPSignedDriver -Filter "DriverProviderName <> 'Microsoft' OR DriverProviderName <> NULL"

The command above runs, but doesn't exclude the NULL entries last one is Fax on my Win10 PC.

The answer to this similar question seems to imply I have it marked right, however theirs is matching to a string whereas I need to exclude a NULL object. I suspect it has to do with the NULL and/or lack of single quotes.

5
  • 1
    The -Filter expects a WQL “where” expression - try IS NULL / IS NOT NULL per learn.microsoft.com/en-us/windows/win32/wmisdk/wql-operators Commented Jun 4, 2021 at 19:10
  • 1
    -Filter "DriverProviderName <> 'Microsoft' and DriverProviderName IS NOT NULL" if you want to exclude the NULL entries… Note the AND connective… Commented Jun 4, 2021 at 19:18
  • 1
    Thanks for both of your feedback. -Filter does work with <>. @JosefZ comment was the solution using AND instead of OR. If you put it as an answer I'll accept it. Commented Jun 4, 2021 at 23:45
  • 2
    As an aside: The CIM cmdlets (e.g., Get-CimInstance) superseded the WMI cmdlets (e.g., Get-WmiObject) in PowerShell v3 (released in September 2012). Therefore, the WMI cmdlets should be avoided, not least because PowerShell [Core] (version 6 and above), where all future effort will go, doesn't even have them anymore. For more information, see this answer. Commented Jun 5, 2021 at 2:08
  • AND not OR. OR allows either case, like TRUE OR FALSE = TRUE. Commented Jun 8, 2021 at 17:14

1 Answer 1

1

It's about translating from English sentences into logical form: When translating from English sentences into logical form, …, and the phrase "neither A nor B" is translated as "not A and not B". Use

Get-WmiObject Win32_PNPSignedDriver -Filter `
  "DriverProviderName <> 'Microsoft' AND DriverProviderName IS NOT NULL"

Note: see Translating “neither…nor” into a mathematical logical expression as well; applying de Morgan's laws, the following code surprisingly works although uses undocumented NOT logical operator in a WQL query:

Get-WmiObject Win32_PNPSignedDriver -Filter `
  "NOT (DriverProviderName = 'Microsoft' OR DriverProviderName IS NULL)"

In above PowerShell code examples is used a backtick to split commands over multiple lines for better readability…

Sign up to request clarification or add additional context in comments.

1 Comment

<> NULL works for me. Using AND is the important part.

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.