__Namespace

Namespace
rootkey : Name

Represents a WMI namespace.

On this page

Main example

List instances

# All instances of __Namespace, with the main properties
Get-CimInstance -ClassName __Namespace -Namespace 'root' |
    Select-Object -Property Name

Examples

Filter with WQL

# WQL filter evaluated by the provider: names starting with "a" (the WQL wildcard is %)
$cimParameters = @{
    ClassName = '__Namespace'
    Namespace = 'root'
    Filter    = "Name LIKE 'a%'"
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name

The filter is evaluated by the WMI provider: less data is transferred than with Where-Object.

Query a remote computer (CIM session)

review before running
# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
    $cimParameters = @{
        CimSession = $cimSession
        ClassName  = '__Namespace'
        Namespace  = 'root'
    }
    Get-CimInstance @cimParameters |
        Select-Object -Property Name
} finally {
    Remove-CimSession -CimSession $cimSession
}

WSMan (WinRM) is used by default. For a host without WinRM, create the session with -SessionOption (New-CimSessionOption -Protocol Dcom). Add -Credential to use another account.

Show the class structure

# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName __Namespace -Namespace 'root'
$cimClass.CimClassProperties |
    Select-Object -Property Name, CimType, Flags

Properties

1 of 1 properties
NameTypeAccessDescription
Name keystringread/write

Namespace name.

Code
# Value of Name for each instance
$cimParameters = @{
    ClassName = '__Namespace'
    Namespace = 'root'
    Property  = 'Name'
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name

Warning. Changes the system: check with -WhatIf first. An elevated console is often required.

# Warning: changes Name on the instance. -WhatIf shows the operation without running it.
# Target instance
$instanceParameters = @{
    ClassName = '__Namespace'
    Namespace = 'root'
    Filter    = "Name = 'Example'"
}
$instance = Get-CimInstance @instanceParameters
$setParameters = @{
    InputObject = $instance
    Property    = @{ Name = 'Example' }
    WhatIf      = $true  # Remove this line to actually apply the change
}
Set-CimInstance @setParameters

Remarks

The __Namespace class is derived from __SystemClass, which has no properties.

You can use __Namespace to identify, create, and delete child namespaces within the current working namespace for which you have an IWbemServices object. Creating a new instance of __Namespace within any working namespace creates a child namespace within the working namespace. Conversely, deleting an instance of __Namespace removes the child namespace from the working namespace. Note that deleting a child namespace also deletes all of its classes and instances.

Enumerating instances of this class within any working namespace gives the available child namespaces.

For example, within the \root namespace are two instances of __Namespace. One has its Name property set to "Default," the other has Name set to "Cimv2." These instances represent the \root\default, and \root\cimv2 namespaces, respectively.

Inheritance

Superclass chain

  1. __SystemClass
  2. __Namespace

Known subclasses

No known subclass.

Requirements

Namespace
root
Minimum client
Windows Vista
Minimum server
Windows Server 2008
DLL
All

Microsoft source

Source: Microsoft Learn

Descriptions, properties and methods come from the Microsoft documentation (MicrosoftDocs/win32 repository), published under the CC BY 4.0 licence. Formatting and translations are specific to this site; the PowerShell examples are written for it.