Reputation: 5504
I am using PowerShell 2.0 and trying to get the possible methods from Win32_ShadowCopy.
Now, when I use Get-WmiObject -list Win32_ShadowCopy | Get-Member
I get:
TypeName: System.Management.ManagementClass#ROOT\cimv2\Win32_ShadowCopy
Name MemberType Definition
---- ---------- ----------
Name AliasProperty Name = __Class
Create Method System.Management.ManagementBaseObject Cre...
...
But if I use Get-WmiObject Win32_ShadowCopy | Get-Member
i get:
TypeName: System.Management.ManagementObject#root\cimv2\Win32_ShadowCopy
Name MemberType Definition
---- ---------- ----------
Revert Method System.Management.ManagementBaseObject Reve...
Caption Property System.String Caption {get;set;}
...
Now I don't understand. Why do I get 2 seemingly different classes? I expect the same result with both commands. I can find what -list
does in the documentation, but not what the default behavior is without the -list
switch. Anyone care to clarify?
Upvotes: 1
Views: 1360
Reputation: 1587
This is from get-help about list.
-List [] Specifies whether to retrieve and display the names of the WMI classes in the WMI repository namespace that is specified in the Namespace para meter. The Default Namespace registry entry in the HKEY_LOCAL_MACHINE\ SOFTWARE\Microsoft\WBEM\Scripting registry key is not used by this cmdl et to determine the default namespace. If you specify the List paramete r but not the Namespace parameter, the root\CIMV2 namespace is used by default.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
for your script
Get-WmiObject -list Win32_ShadowCopy
equals:
Get-WmiObject -list -class Win32_ShadowCopy
which means you're listing classes with name Win32_ShadowCopy.
And the
Get-WmiObject Win32_ShadowCopy
equals:
Get-WmiObject -Class Win32_ShadowCopy
which returns the objects of the specified class.
Upvotes: 2
Reputation: 8660
Get-WmiObject by default will return instances of the given class.
Get-WmiObject -List on the other hand will return class itself. Latter is mainly useful when wildcards are used (e.g. to list all classes in default - root\cimv2 namespace with Disk in name you can do Get-WmiObject -Class *Disk* -List
).
Upvotes: 1