powershellwmiwqlget-wmiobject

Get-WmiObject -Filter OR not working with NULL


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.


Solution

  • 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…