Using a NOT Statement in a WMI Query
John Savill
November 13, 2007
1 Min Read
Q. I'm trying to write a Windows Management Instrumentation (WMI) query that contains a NOT statement. Why isn't it working?
A. A WMI query can select attributes based on a certain value. For example, if I want to list all partitions that are NTFS, I would use
strComputer = "."Set WshShell = WScript.CreateObject("WScript.Shell")Dim WshShellSet objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")Set colFileSystems = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk where FileSystem = 'NTFS'")For Each objFileSystem in colFileSystems wscript.echo objFileSystem.Caption & " " & objFileSystem.FileSystemNext
Notice the format of the WMI Query Language?
Select * from Win32_LogicalDisk where FileSystem = 'NTFS'
When I run the script, it will list all partitions that are NTFS. If I want to see all partitions that are not NTFS, placing NOT in front of the equal sign doesn't work. Instead, you must place NOT in front of the attribute being checked, as this example shows:
Select * from Win32_LogicalDisk where NOT FileSystem = 'NTFS'
— John Savill
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like