Search code examples
sqlpowershellwmiwql

Formatting WQL Query in powershell


I'm trying to format a WQL Query in powershell to look only for the Wired Ethernet adapter by using the following code

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Name LIKE '%Ethernet%' OR '%Gigabit%'" -CN "." | Out-Host

However I dont have much knowledge of SQL/WQL and im not sure if im formatting the OR statement correctly in PS if someone could point me in the right direction I would appreciate it.

Thanks!


Solution

  • Here's the documentation on WQL operators and the WQL WHERE clause

    Based on the documentation, your method is correct, but your syntax was off. If you are on PSv3+, I'd suggest using the CIM cmdlets as the WMI ones are technically deprecated.

    Get-CimInstance -Query 'SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Name LIKE "%ethernet%" OR Name LIKE "%gigabit%"'
    

    In your example:

    Get-WmiObject -Class 'Win32_NetworkAdapterConfiguration' -Filter 'Name LIKE "%ethernet%" OR Name LIKE "%gigabit%"' -ComputerName '.'
    

    Additionally, @Avshalom is correct in that your field is wrong. You want to be looking at the 'Description'.

    Get-WmiObject -Filter 'Description LIKE "%ethernet%" OR Description LIKE "%gigabit%"' -Class 'Win32_NetworkAdapterConfiguration' -ComputerName '.'