Win32_Directory

The Win32_Directory WMI class represents a directory entry on a computer system running Windows. A directory is a type of file that logically groups data files and provides path information for the...

The Win32_Directory WMI class represents a directory entry on a computer system running Windows. A directory is a type of file that logically groups data files and provides path information for the grouped files. Example: C:\TEMP. Win32_Directory does not include directories of network drives.

Methods

Win32_Directory has 14 methods:
Method Description
ChangeSecurityPermissions Class method that changes the security permissions for the logical file specified in the object path.
ChangeSecurityPermissionsEx Class method that changes the security permissions for the logical file specified in the object path.
Compress Class method that compresses the logical file (or directory) specified in the object path.
CompressEx Class method that compresses the logical file (or directory) specified in the object path.
Copy Class method that copies the logical file or directory specified in the object path to the location specified by the input parameter.
CopyEx Class method that copies the logical file or directory specified in the object path to the location specified by the <em>FileName</em> parameter.
Delete Class method that deletes the logical file (or directory) specified in the object path.
DeleteEx Class method that deletes the logical file (or directory) specified in the object path.
GetEffectivePermission Class method that determines whether the caller has the aggregated permissions specified by the <em>Permissions</em> argument not only on the file object, but on the share the file or directory resides on (if it is on a share).
Rename Class method that renames the logical file (or directory) specified in the object path.
TakeOwnerShip Class method that obtains ownership of the logical file specified in the object path.
TakeOwnerShipEx Class method that obtains ownership of the logical file specified in the object path.
Uncompress Class method that uncompresses the logical file (or directory) specified in the object path.
UncompressEx Class method that uncompresses the logical file (or directory) specified in the object path.

Learn more about Invoke-CimMethod and how to invoke commands. Click any of the methods listed above to learn more about their purpose, parameters, and return value.

Properties

Win32_Directory returns 31 properties:

'AccessMask','Archive','Caption','Compressed','CompressionMethod','CreationClassName',
'CreationDate','CSCreationClassName','CSName','Description','Drive','EightDotThreeFileName',
'Encrypted','EncryptionMethod','Extension','FileName','FileSize','FileType','FSCreationClassName',
'FSName','Hidden','InstallDate','InUseCount','LastAccessed','LastModified','Name','Path',
'Readable','Status','System','Writeable'

Unless explicitly marked as writeable, all properties are read-only. Read all properties for all instances:

Get-CimInstance -ClassName Win32_Directory -Property *

Most WMI classes return one or more instances.

When Get-CimInstance returns no result, then apparently no instances of class Win32_Directory exist. This is normal behavior.

Either the class is not implemented on your system (may be deprecated or due to missing drivers, i.e. CIM_VideoControllerResolution), or there are simply no physical representations of this class currently available (i.e. Win32_TapeDrive).

AccessMask

UINT32

Bitmask that represents the access rights required to access or perform specific operations on the directory. For bit values, see File and Directory Access Rights Constants.

Note

On FAT volumes, the FULL_ACCESS value is returned instead, which indicates no security has been set on the object.

AccessMask returns a numeric value. To translate it into a meaningful text, use any of the following approaches:

Use a PowerShell Hashtable
$AccessMask_map = @{
      1 = 'FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory)'
      2 = 'FILE_WRITE_DATA (file) or FILE_ADD_FILE (directory)'
      4 = 'FILE_APPEND_DATA (file) or FILE_ADD_SUBDIRECTORY'
      8 = 'FILE_READ_EA'
     16 = 'FILE_WRITE_EA'
     32 = 'FILE_EXECUTE (file) or FILE_TRAVERSE (directory)'
     64 = 'FILE_DELETE_CHILD (directory)'
    128 = 'FILE_READ_ATTRIBUTES'
    256 = 'FILE_WRITE_ATTRIBUTES'
  65536 = 'DELETE'
 131072 = 'READ_CONTROL'
 262144 = 'WRITE_DAC'
 524288 = 'WRITE_OWNER'
1048576 = 'SYNCHRONIZE'
18809343 = 'ACCESS_SYSTEM_SECURITY'
}
Use a switch statement
switch([int]$value)
{
  1          {'FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory)'}
  2          {'FILE_WRITE_DATA (file) or FILE_ADD_FILE (directory)'}
  4          {'FILE_APPEND_DATA (file) or FILE_ADD_SUBDIRECTORY'}
  8          {'FILE_READ_EA'}
  16         {'FILE_WRITE_EA'}
  32         {'FILE_EXECUTE (file) or FILE_TRAVERSE (directory)'}
  64         {'FILE_DELETE_CHILD (directory)'}
  128        {'FILE_READ_ATTRIBUTES'}
  256        {'FILE_WRITE_ATTRIBUTES'}
  65536      {'DELETE'}
  131072     {'READ_CONTROL'}
  262144     {'WRITE_DAC'}
  524288     {'WRITE_OWNER'}
  1048576    {'SYNCHRONIZE'}
  18809343   {'ACCESS_SYSTEM_SECURITY'}
  default    {"$value"}
}
Use Enum structure
Enum EnumAccessMask
{
  FILE_READ_DATA_file_or_FILE_LIST_DIRECTORY_directory   = 1
  FILE_WRITE_DATA_file_or_FILE_ADD_FILE_directory        = 2
  FILE_APPEND_DATA_file_or_FILE_ADD_SUBDIRECTORY         = 4
  FILE_READ_EA                                           = 8
  FILE_WRITE_EA                                          = 16
  FILE_EXECUTE_file_or_FILE_TRAVERSE_directory           = 32
  FILE_DELETE_CHILD_directory                            = 64
  FILE_READ_ATTRIBUTES                                   = 128
  FILE_WRITE_ATTRIBUTES                                  = 256
  DELETE                                                 = 65536
  READ_CONTROL                                           = 131072
  WRITE_DAC                                              = 262144
  WRITE_OWNER                                            = 524288
  SYNCHRONIZE                                            = 1048576
  ACCESS_SYSTEM_SECURITY                                 = 18809343
}

Examples

Use $AccessMask_map in a calculated property for Select-Object
<# 
  this example uses a hashtable to translate raw numeric values for 
  property "AccessMask" to friendly text

  Note: to use other properties than "AccessMask", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "AccessMask" 
# to translate other properties, use their translation table instead
$AccessMask_map = @{
      1 = 'FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory)'
      2 = 'FILE_WRITE_DATA (file) or FILE_ADD_FILE (directory)'
      4 = 'FILE_APPEND_DATA (file) or FILE_ADD_SUBDIRECTORY'
      8 = 'FILE_READ_EA'
     16 = 'FILE_WRITE_EA'
     32 = 'FILE_EXECUTE (file) or FILE_TRAVERSE (directory)'
     64 = 'FILE_DELETE_CHILD (directory)'
    128 = 'FILE_READ_ATTRIBUTES'
    256 = 'FILE_WRITE_ATTRIBUTES'
  65536 = 'DELETE'
 131072 = 'READ_CONTROL'
 262144 = 'WRITE_DAC'
 524288 = 'WRITE_OWNER'
1048576 = 'SYNCHRONIZE'
18809343 = 'ACCESS_SYSTEM_SECURITY'
}

#endregion define hashtable

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "AccessMask", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$AccessMask = @{
  Name = 'AccessMask'
  Expression = {
    # property is an array, so process all values
    $value = $_.AccessMask
    $AccessMask_map[[int]$value]
  }  
}
#endregion define calculated property

# retrieve the instances, and output the properties "Caption" and "AccessMask". The latter
# is defined by the hashtable in $AccessMask: 
Get-CimInstance -Class Win32_Directory | Select-Object -Property Caption, $AccessMask

# ...or dump content of property AccessMask:
$friendlyValues = Get-CimInstance -Class Win32_Directory | 
    Select-Object -Property $AccessMask |
    Select-Object -ExpandProperty AccessMask

# output values
$friendlyValues

# output values as comma separated list
$friendlyValues -join ', '

# output values as bullet list
$friendlyValues | ForEach-Object { "- $_" }
Use $AccessMask_map to directly translate raw values from an instance
<# 
  this example uses a hashtable to manually translate raw numeric values 
  for property "Win32_Directory" to friendly text. This approach is ideal when
  there is just one instance to work with.

  Note: to use other properties than "Win32_Directory", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "Win32_Directory" 
# to translate other properties, use their translation table instead
$AccessMask_map = @{
      1 = 'FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory)'
      2 = 'FILE_WRITE_DATA (file) or FILE_ADD_FILE (directory)'
      4 = 'FILE_APPEND_DATA (file) or FILE_ADD_SUBDIRECTORY'
      8 = 'FILE_READ_EA'
     16 = 'FILE_WRITE_EA'
     32 = 'FILE_EXECUTE (file) or FILE_TRAVERSE (directory)'
     64 = 'FILE_DELETE_CHILD (directory)'
    128 = 'FILE_READ_ATTRIBUTES'
    256 = 'FILE_WRITE_ATTRIBUTES'
  65536 = 'DELETE'
 131072 = 'READ_CONTROL'
 262144 = 'WRITE_DAC'
 524288 = 'WRITE_OWNER'
1048576 = 'SYNCHRONIZE'
18809343 = 'ACCESS_SYSTEM_SECURITY'
}

#endregion define hashtable

# get one instance:
$instance = Get-CimInstance -Class Win32_Directory | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to illustrate
  the number-to-text translation. To process all instances, replace
  "Select-Object -First 1" with a "Foreach-Object" loop, and use
  the iterator variable $_ instead of $instance
#>

# query the property
$rawValue = $instance.AccessMask  

# translate raw value to friendly text:
$friendlyName = $AccessMask_map[[int]$rawValue]

# output value
$friendlyName
Use a switch statement inside a calculated property for Select-Object
<# 
  this example uses a switch clause to translate raw numeric 
  values for property "AccessMask" to friendly text. The switch
  clause is embedded into a calculated property so there is
  no need to refer to external variables for translation.

  Note: to use other properties than "AccessMask", look up the appropriate 
  translation switch clause for the property you would like to use instead.
#>

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "AccessMask", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$AccessMask = @{
  Name = 'AccessMask'
  Expression = {
    # property is an array, so process all values
    $value = $_.AccessMask
    
    switch([int]$value)
      {
        1          {'FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory)'}
        2          {'FILE_WRITE_DATA (file) or FILE_ADD_FILE (directory)'}
        4          {'FILE_APPEND_DATA (file) or FILE_ADD_SUBDIRECTORY'}
        8          {'FILE_READ_EA'}
        16         {'FILE_WRITE_EA'}
        32         {'FILE_EXECUTE (file) or FILE_TRAVERSE (directory)'}
        64         {'FILE_DELETE_CHILD (directory)'}
        128        {'FILE_READ_ATTRIBUTES'}
        256        {'FILE_WRITE_ATTRIBUTES'}
        65536      {'DELETE'}
        131072     {'READ_CONTROL'}
        262144     {'WRITE_DAC'}
        524288     {'WRITE_OWNER'}
        1048576    {'SYNCHRONIZE'}
        18809343   {'ACCESS_SYSTEM_SECURITY'}
        default    {"$value"}
      }
      
  }  
}
#endregion define calculated property

# retrieve all instances...
Get-CimInstance -ClassName Win32_Directory | 
  # ...and output properties "Caption" and "AccessMask". The latter is defined
  # by the hashtable in $AccessMask:
  Select-Object -Property Caption, $AccessMask
Use the Enum from above to auto-translate the code values
<# 
  this example translates raw values by means of type conversion
  the friendly names are defined as enumeration using the
  keyword "enum" (PowerShell 5 or better)
  
  The raw value(s) are translated to friendly text by 
  simply converting them into the enum type.
  
  Note: to use other properties than "Win32_Directory", look up the appropriate 
  enum definition for the property you would like to use instead.
#>


#region define enum with value-to-text translation:
Enum EnumAccessMask
{
  FILE_READ_DATA_file_or_FILE_LIST_DIRECTORY_directory   = 1
  FILE_WRITE_DATA_file_or_FILE_ADD_FILE_directory        = 2
  FILE_APPEND_DATA_file_or_FILE_ADD_SUBDIRECTORY         = 4
  FILE_READ_EA                                           = 8
  FILE_WRITE_EA                                          = 16
  FILE_EXECUTE_file_or_FILE_TRAVERSE_directory           = 32
  FILE_DELETE_CHILD_directory                            = 64
  FILE_READ_ATTRIBUTES                                   = 128
  FILE_WRITE_ATTRIBUTES                                  = 256
  DELETE                                                 = 65536
  READ_CONTROL                                           = 131072
  WRITE_DAC                                              = 262144
  WRITE_OWNER                                            = 524288
  SYNCHRONIZE                                            = 1048576
  ACCESS_SYSTEM_SECURITY                                 = 18809343
}

#endregion define enum

# get one instance:
$instance = Get-CimInstance -Class Win32_Directory | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to focus on
  the number-to-text type conversion. 
  
  To process all instances, replace   "Select-Object -First 1" 
  with a "Foreach-Object" loop, and use the iterator variable 
  $_ instead of $instance
#>

# query the property:
$rawValue = $instance.AccessMask

#region using strict type conversion

<#
  Note: strict type conversion fails if the raw value is 
  not defined by the enum. So if the list of allowable values
  was extended and the enum does not match the value,
  an exception is thrown
#>

# convert the property to the enum **AccessMask** 
[EnumAccessMask]$rawValue 

# get a comma-separated string:
[EnumAccessMask]$rawValue -join ',' 
#endregion

#region using operator "-as"

<#
  Note: the operator "-as" accepts values not defined
  by the enum and returns $null instead of throwing
  an exception
#>

$rawValue -as [EnumAccessMask]
#endregion

Enums must cover all possible values. If AccessMask returns a value that is not defined in the enum, an exception occurs. The exception reports the value that was missing in the enum. To fix, add the missing value to the enum.

Archive

BOOLEAN

Indicates whether the archive bit on the folder has been set. The archive bit is used by backup programs to identify files that should be backed up. If True, the file should be archived.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, Archive

Caption

STRING MAX 64 CHAR

A short textual description of the object.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, Caption

Compressed

BOOLEAN

Indicates whether or not the folder has been compressed. WMI recognizes folders compressed using WMI itself or using the graphical user interface; it does not, however, recognize .ZIP files as being compressed. If True, the file is compressed.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, Compressed

CompressionMethod

STRING

Algorithm or tool (usually a method) used to compress the logical file. If it is not possible (or not desired) to describe the compression scheme (perhaps because it is not known), use the following words: “Unknown” to represent that it is not known whether the logical file is compressed; “Compressed” to represent that the file is compressed, but either its compression scheme is not known or not disclosed; and “Not Compressed” to represent that the logical file is not compressed.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, CompressionMethod

CreationClassName

STRING

Name of the first concrete class to appear in the inheritance chain used in the creation of an instance. When used with the other key properties of the class, this property allows all instances of this class and its subclasses to be uniquely identified.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, CreationClassName

CreationDate

DATETIME

Date that the file system object was created. For more information on working with WMI date and time formats, see WMI Tasks: Dates and Times.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, CreationDate

CSCreationClassName

STRING

Creation class name of the scoping computer system.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, CSCreationClassName

CSName

STRING

Name of the computer where the file system object is stored.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, CSName

Description

STRING

A textual description of the object.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, Description

Drive

STRING

Drive letter of the drive (including colon) where the file system object is stored.

Example: “c:”

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, Drive

EightDotThreeFileName

STRING

MS-DOS -compatible name for the folder.

Example: “c:\progra~1”

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, EightDotThreeFileName

Encrypted

BOOLEAN

Indicates whether or not the folder has been encrypted. If True, the folder is encrypted.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, Encrypted

EncryptionMethod

STRING

Algorithm or tool used to encrypt the logical file. If it is not possible (or not desired) to describe the encryption scheme (perhaps for security reasons), use the following words: “Unknown” to represent that it is not known whether the logical file is encrypted; “Encrypted” to represent that the file is encrypted, but either its encryption scheme is not known or not disclosed; and “Not Encrypted” to represent that the logical file is not encrypted.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, EncryptionMethod

Extension

STRING

File name extension for the file system object, not including the dot (.) that separates the extension from the file name.

Examples: “txt”, “mof”, “mdb”

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, Extension

FileName

STRING

File name (without the dot or extension) of the file.

Example: “autoexec”

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, FileName

FileSize

UINT64 “BYTES”

Size of the file system object, in bytes. Although folders possess a FileSize property, the value 0 is always returned. To determine the size of a folder, use the FileSystemObject or add up the size of all the files stored in the folder.

For more information about using uint64 values in scripts, see Scripting in WMI.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, FileSize

FileType

STRING

File type (indicated by the Extension property).

For example, an .mdb file is likely to have the file type Microsoft Access Application. An .asp file likely has the file type HTML Document. Folders are typically reported simply as Folder.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, FileType

FSCreationClassName

STRING

Class of the file system.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, FSCreationClassName

FSName

STRING

Type of file system (NTFS, FAT, FAT32) installed on the drive where the file or folder is located.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, FSName

Hidden

BOOLEAN

Indicates whether the file system object is hidden. If True, the file is hidden.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, Hidden

InstallDate

DATETIME

Indicates when the object was installed. Lack of a value does not indicate that the object is not installed.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, InstallDate

InUseCount

UINT64

Number of “file opens” that are currently active against the file.

For more information about using uint64 values in scripts, see Scripting in WMI.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, InUseCount

LastAccessed

DATETIME

Date the file was last accessed. For more information on working with WMI date and time formats, see WMI Tasks: Dates and Times.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, LastAccessed

LastModified

DATETIME

Date the file was last modified. For more information on working with WMI date and time formats, see WMI Tasks: Dates and Times.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, LastModified

Name

KEY PROPERTY STRING

The Name property is a string representing the inherited name that serves as a key of a logical file instance within a file system. Full path names should be provided. Example: C:\Windows\system\win.ini

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name

Path

STRING

Path for the file. The path includes the leading and trailing backslashes, but not the drive letter or the folder name.

For the folder c:\windows\system32\wbem, the path is \windows\system32. For the folder c:\scripts, the path is .

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, Path

Readable

BOOLEAN

Indicates whether you can read items in the folder. If True, the file can be read.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, Readable

Status

STRING MAX 10 CHAR

Current status of an object. Various operational and nonoperational statuses can be defined. Available values:

$values = 'Degraded','Error','Lost Comm','No Contact','NonRecover','OK','Pred Fail','Service','Starting','Stopping','Stressed','Unknown'
Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, Status

System

BOOLEAN

Indicates whether the object is a system file. If True, the file is a system file

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, System

Writeable

BOOLEAN

If True, the file can be written.

Get-CimInstance -ClassName Win32_Directory | Select-Object -Property Name, Writeable

Examples

List all instances of Win32_Directory
Get-CimInstance -ClassName Win32_Directory

Learn more about Get-CimInstance and the deprecated Get-WmiObject.

View all properties
Get-CimInstance -ClassName Win32_Directory -Property *
View key properties only
Get-CimInstance -ClassName Win32_Directory -KeyOnly

Selecting Properties

To select only some properties, pipe the results to Select-Object -Property a,b,c with a comma-separated list of the properties you require. Wildcards are permitted.

Get-CimInstance always returns all properties but only retrieves the ones that you specify. All other properties are empty but still present. That’s why you need to pipe the results into Select-Object if you want to limit the visible properties, i.e. for reporting.

Selecting Properties

The code below lists all available properties. Remove the ones you do not need:

$properties = 'AccessMask',
              'Archive',
              'Caption',
              'Compressed',
              'CompressionMethod',
              'CreationClassName',
              'CreationDate',
              'CSCreationClassName',
              'CSName',
              'Description',
              'Drive',
              'EightDotThreeFileName',
              'Encrypted',
              'EncryptionMethod',
              'Extension',
              'FileName',
              'FileSize',
              'FileType',
              'FSCreationClassName',
              'FSName',
              'Hidden',
              'InstallDate',
              'InUseCount',
              'LastAccessed',
              'LastModified',
              'Name',
              'Path',
              'Readable',
              'Status',
              'System',
              'Writeable'
Get-CimInstance -ClassName Win32_Directory | Select-Object -Property $properties
Limiting Network Bandwidth

If you work remotely, it makes sense to limit network bandwidth by filtering the properties on the server side, too:

Get-CimInstance -Class Win32_Directory -Property $property | 
Select-Object -Property $property

Selecting Instances

To select some instances, use Get-CimInstance and a WMI Query. The wildcard character in WMI Queries is % (and not “*”).

The parameter -Filter runs a simple query.

Listing all instances where the property Caption starts with “A”
Get-CimInstance -Class Win32_Directory -Filter 'Caption LIKE "a%"' 
Using a WQL Query

The parameter -Query uses a query similar to SQL and combines the parameters -Filter and -Property. This returns all instances where the property Caption starts with “A”, and returns the properties specified:

Get-CimInstance -Query "SELECT InUseCount, Readable, EncryptionMethod, Hidden FROM Win32_Directory WHERE Caption LIKE 'a%'"

Any property you did not specify is still present but empty. You might need to use Select-Object to remove all unwanted properties:

Get-CimInstance -Query "SELECT InUseCount, Readable, EncryptionMethod, Hidden FROM Win32_Directory WHERE Caption LIKE 'a%'" | Select-Object -Property InUseCount, Readable, EncryptionMethod, Hidden

Accessing Remote Computers

To access remote systems, you need to have proper permissions. User the parameter -ComputerName to access one or more remote systems.

Authenticating as Current User
# one or more computer names or IP addresses:
$list = 'server1', 'server2'

# authenticate with your current identity:
$result = Get-CimInstance -ClassName Win32_Directory -ComputerName $list 
$result
Authenticating as Different User

Use a CIMSession object to authenticate with a new identity:

# one or more computer names or IP addresses:
$list = 'server1', 'server2'

# authenticate with a different identity:
$cred = Get-Credential -Message 'Authenticate to retrieve WMI information:'
$session = New-CimSession -ComputerName $list -Credential $cred

$result = Get-CimInstance Win32_Directory -CimSession $session

# remove the session after use (if you do not plan to re-use it later)
Remove-CimSession -CimSession $session

$result

Learn more about accessing remote computers.

Requirements

To use Win32_Directory, the following requirements apply:

PowerShell

Get-CimInstance was introduced with PowerShell Version 3.0, which in turn was introduced on clients with Windows 8 and on servers with Windows Server 2012.

If necessary, update Windows PowerShell to Windows PowerShell 5.1, or install PowerShell 7 side-by-side.

Operating System

Win32_Directory was introduced on clients with Windows Vista and on servers with Windows Server 2008.

Namespace

Win32_Directory lives in the Namespace Root/CIMV2. This is the default namespace. There is no need to use the -Namespace parameter in Get-CimInstance.

Implementation

Win32_Directory is implemented in CIMWin32.dll and defined in CIMWin32.mof. Both files are located in the folder C:\Windows\system32\wbem:

explorer $env:windir\system32\wbem
notepad $env:windir\system32\wbem\CIMWin32.mof