Using a NOT Statement in a WMI Query

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 WshShell
Set objWMIService = GetObject("winmgmts:" & "\{impersonationLevel=impersonate\}!\\" & strComputer & "\root\cimv2")
Set colFileSystems = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk where FileSystem = 'NTFS'")
For Each objFileSystem in colFileSystems
  wscript.echo objFileSystem.Caption & " " & objFileSystem.FileSystem
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'
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.