Goku Sensei
Goku Sensei

Reputation: 33

How can i list namespaces under the root?

I want to list which things are useable under \\root\ .However i don't know how to list or see which things i can use.Because,i am beginner in the powershell.

I am coding this thing: wmic /namespace:\root\ (But i don't know which things i can use under root.And because of this, i cannot use anything :/)

How can i list which things could be useable under root ? If someone can help, i will be really happy :D

I tried use "/?" but it didn't help.Also i researched on google BUT again i couldn't find something useful for myself or maybe i couldn't understand their solutions.

Upvotes: 3

Views: 5102

Answers (2)

mklement0
mklement0

Reputation: 438263

Cpt.Whale's answer is helpful, but is uses the deprecated WMI cmdlets (from the Get-WmiObject docs page: "Starting in PowerShell 3.0, this cmdlet has been superseded by Get-CimInstance"); similarly, wmic.exe is deprecated (see note at the top of the page). Both are deprecated in favor of the CIM cmdlets, so the standard advice applies:

  • The CIM cmdlets (e.g., Get-CimInstance) superseded the WMI cmdlets (e.g., Get-WmiObject) in PowerShell v3 (released in September 2012). Therefore, the WMI cmdlets should be avoided, not least because PowerShell (Core) v7+, where all future effort will go, doesn't even have them anymore. Note that WMI still underlies the CIM cmdlets, however.
  • For more information, including the differences between these two sets of cmdlets, see this answer.

Thus, here are solutions based on the CIM cmdlets:

  • To get all namespaces nested inside another namespace, such as root:
Get-CimInstance -Class __Namespace -Namespace root | ForEach-Object Name
  • To get all classes inside a given namespace, such as root, by name:
Get-CimClass -Namespace root | ForEach-Object CimClassName

Note:

  • Append | Sort-Object to the commands above to get alphabetically sorted output.

  • The default namespace (also for the WMI cmdlets) is root/cimv2, which applies if you omit a -Namespace argument.

Upvotes: 5

Cpt.Whale
Cpt.Whale

Reputation: 5341

There is a WMI class of __namespace you can query:

Get-WmiObject -Namespace Root -Class __Namespace | Select Name

Name           
----           
subscription   
DEFAULT        
CIMV2          
msdtc          
Cli            
SECURITY       
SecurityCenter2
RSOP           
PEH            
StandardCimv2  
WMI            
MSPS           
directory      
Policy         
Interop        
Hardware       
ServiceModel   
SecurityCenter 
Microsoft      
Appv           

I would recommend reading through about WMI. It covers some of the discoverability aspects, which are important because:

In a default installation of Windows 8, there are more than 1,100 WMI classes in Root/Cimv2


Newer versions of powershell use CIM over WMI with commands like Get-CimInstance. It's not worth worrying about for now, but it's good to look into while you're learning

WMIC is a separate exe from powershell, and doesn't return powershell objects. I would avoid it unless you're stuck to command prompt

Upvotes: 5

Related Questions