I have a test Windows XP SP3 clean install with power shell. It’s a very strange difference if i access WMI from PowerShell and from VBScript. From powershell:
Get-WmiObject 'Win32_OperatingSystem" | select Caption
This correctly displays “Windows XP Professional”. And same code written as VBScript:
WScript.Echo( GetObject( "winmgmts:Win32_OperatingSystem" ).Caption )
Displays “null” O_O. Why this happens?
Here is the VBScript equivalent:
Although there is only one Operating System, a WMI query always returns a list.
Ok, now, the difference – Using the
Get-WmiObjectcmdlet, since there is only one operation system, you get the object directly rather than a list when you doGet-WmiObject "Win32_OperatingSystem"( use GetType to see that this is actually of typeSystem.Management.ManagementObject)Since there will be multiple processes,
get-wmiobject win32_processwould give a array. ( use GetType to see that this is of typeSystem.Object[]The following would not give any output:
Whereas the below would: