Pardon if this is something simple, tried google, and the search function here with some similiar questions, just no answer that worked for me in this scenario.
For the sake of trying to avoid the pipeline as much as possible, I was reading into the WQL queries offered using the -Query
parameter in Get-CimInstance
. In my mind, it's a simple query (unless i'm missing something) that should select the MACAddress, IPAddress, from the class of Win32_NetworkAdapterConfiguration, from the available instance of where the property of IPAddress is not null.
Get-CimInstance -Query "SELECT MACAddress, IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPAddress != NULL"
At first, I thought it was a mistake on my end since the exception thrown, reads off a message saying the query is invalid, yet this works:
Get-CimInstance -Query "SELECT MACAddress, IPAddress FROM Win32_NetworkAdapterConfiguration WHERE MACAddress != NULL"
# or - using -Filter
Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter "MACAddress != NULL"
May I get some guidance on this? Perhaps share an alternate solution to this question?
IPAddress is a valid property which I could easily filter through using the Where-Object
but, looking to learn something new and understand WQL a little better.
[...] looking to learn something new and understand WQL a little better.
There's really only one thing about WQL you need to understand here[1]:
So your initial instinct to filter with Where-Object
is spot on :)
The correct syntax for filtering out instances with NULL values (assuming you were filtering on a property of a scalar type, here exemplified using the MACAddress
property) would be:
SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress IS NOT NULL