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!
Win32_NetworkAdapterConfiguration
has no Name
Property.
Anyway regarding your question you can use the filter this way, in the example i'm using valid property like ServiceName
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "ServiceName like '%msloop%' or ServiceName like '%tunnel%'"
Also, you don't have to Provide a ComputerName
Parameter for the local computer, it's the default
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 '.'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.