Is it possible to use NOT LIKE in WQL when using Get-WMIOBJECT

rated by 0 users
This post has 4 Replies | 1 Follower

Not Ranked
Posts 5
JoB Posted: 05-06-2012 4:46 AM

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 

Top 25 Contributor
Posts 296
Microsoft MVP
Top Contributor

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

Not Ranked
Posts 5

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%')"

Jo

Not Ranked
Posts 5

Hello

Actually I just checked and the statement without the inner set of brackets in 5 milliseconds faster

Jo

Top 25 Contributor
Posts 296
Microsoft MVP
Top Contributor

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

 

Page 1 of 1 (5 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.