Hello,
I canot see a way to use a NOT LIKE statement in WQL for example
Get-WmiObject -query "select SerialNumber FROM win32_bios WHERE SerialNumber LIKE 'to be filled by O.E.M%'"
Gets my BIOS Serial Number as it is set to, to be filled by O.E.M
However I want to say WHERE NOT LIKE, I see you can you <> or != for non strings. However there does not appear to be a NOTLIKE or [NOT]LIKE in WQL
I know I could do this for example
(Get-WMIOBJECT Win32_BIOS).SerialNumber | where {$_ -notmatch "^to be filled by O.E.M"}
However lets say I have 1000 computers, I would have to pass all of there SerialNumbers down the pipline then filter, I wanted early filtering with WQL
is there a WQL sollution to the above?
Thanks All
Jo
Try this
Get-WmiObject -Query "SELECT SerialNumber FROM Win32_Bios WHERE NOT SerialNumber LIKE 'to be filled by O.E.M%'"
Notice where the NOT sits in the syntax - not intuitive
This also works
Get-WmiObject -Class Win32_Bios -Filter "NOT SerialNumber LIKE 'to be filled by O.E.M%'" -Property SerialNumber
Thanks very much Richard, so that's how you do it like you way not too obvious. For ease of reading I will use this
Get-WmiObject -query "select SerialNumber FROM win32_bios WHERE NOT (SerialNumber LIKE 'to be filled by O.E.M%')"
Hello
Actually I just checked and the statement without the inner set of brackets in 5 milliseconds faster
Couple of points on timing PowerShell statements:
first run the timing a good number of times - I generally use 100 - to even out fluctuations in machine performance
second in this case I suspect that the difference is due to the way PowerShell interprets the brackets and their contents - you generally don't need them in WQL