Main example
List instances
# All instances of Win32_LogicalDisk, with the main properties
Get-CimInstance -ClassName Win32_LogicalDisk |
Select-Object -Property @(
'DeviceID'
'VolumeName'
'FileSystem'
@{ Name = 'SizeGB'; Expression = { [math]::Round($_.Size / 1GB, 2) } }
@{ Name = 'FreeSpaceGB'; Expression = { [math]::Round($_.FreeSpace / 1GB, 2) } }
'DriveType'
)Examples
Filter with WQL
# WQL filter evaluated by the provider: DriveType = 3 (Local Disk)
Get-CimInstance -ClassName Win32_LogicalDisk -Filter 'DriveType = 3' |
Select-Object -Property @(
'DeviceID'
'VolumeName'
'FileSystem'
@{ Name = 'SizeGB'; Expression = { [math]::Round($_.Size / 1GB, 2) } }
@{ Name = 'FreeSpaceGB'; Expression = { [math]::Round($_.FreeSpace / 1GB, 2) } }
'DriveType'
)The filter is evaluated by the WMI provider: less data is transferred than with Where-Object.
Decode numeric values
# Lookup table for DriveType (values documented by Microsoft)
$driveTypeName = @{
0 = 'Unknown'
1 = 'No Root Directory'
2 = 'Removable Disk'
3 = 'Local Disk'
4 = 'Network Drive'
5 = 'Compact Disc'
6 = 'RAM Disk'
}
# Lookup table for Access (values documented by Microsoft)
$accessName = @{
0 = 'Unknown'
1 = 'Readable'
2 = 'Writeable'
3 = 'Read/Write Supported'
4 = 'Write Once'
}
Get-CimInstance -ClassName Win32_LogicalDisk |
Select-Object -Property @(
'DeviceID'
'VolumeName'
'FileSystem'
@{ Name = 'SizeGB'; Expression = { [math]::Round($_.Size / 1GB, 2) } }
@{ Name = 'FreeSpaceGB'; Expression = { [math]::Round($_.FreeSpace / 1GB, 2) } }
@{ Name = 'DriveType'; Expression = { $driveTypeName[[int]$_.DriveType] } }
@{ Name = 'Access'; Expression = { $accessName[[int]$_.Access] } }
)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 {
Get-CimInstance -CimSession $cimSession -ClassName Win32_LogicalDisk |
Select-Object -Property @(
'DeviceID'
'VolumeName'
'FileSystem'
@{ Name = 'SizeGB'; Expression = { [math]::Round($_.Size / 1GB, 2) } }
@{ Name = 'FreeSpaceGB'; Expression = { [math]::Round($_.FreeSpace / 1GB, 2) } }
'DriveType'
)
} 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 Win32_LogicalDisk
$cimClass.CimClassProperties |
Select-Object -Property Name, CimType, Flags
# Methods of the class
$cimClass.CimClassMethods |
Select-Object -Property Name, ReturnTypeProperties
| Name | Type | Access | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Access# | uint16 | read | Type of media access available. Values (5)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Availability# | uint16 | read | Availability and status of the device. Values (21)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BlockSize# | uint64 | read | Size, in bytes, of the blocks that form this storage extent. If unknown or if a block concept is not valid (for example, for aggregate extents, memory or logical disks), enter 1. For more information about using uint64 values in scripts, see Scripting in WMI. Unit: bytes Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Caption# | string | read | Short description of the object a one-line string. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compressed# | boolean | read | If True, the logical volume exists as a single compressed entity, such as a DoubleSpace volume. If file based compression is supported, such as on NTFS, this property is False. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigManagerErrorCode# | uint32 | read | Windows Configuration Manager error code. Values (32)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigManagerUserConfig# | boolean | read | If True, the device is using a user-defined configuration. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CreationClassName# key | string | read | 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, the property allows all instances of this class and its subclasses to be uniquely identified. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description# | string | read | Description of the object. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DeviceID# key | string | read | Unique identifier of the logical disk from other devices on the system. For a code example that retrieves this property, see the Remarks section, below. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DriveType# | uint32 | read | Numeric value that corresponds to the type of disk drive this logical disk represents. Values (7)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ErrorCleared# | boolean | read | If True, the error reported in LastErrorCode is now cleared. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ErrorDescription# | string | read | More information about the error recorded in LastErrorCode, and information on any corrective actions that may be taken. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ErrorMethodology# | string | read | Type of error detection and correction supported by this storage extent. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FileSystem# | string | read | File system on the logical disk. Example: "NTFS" Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FreeSpace# | uint64 | read | Space, in bytes, available on the logical disk. For more information about using uint64 values in scripts, see Scripting in WMI. Unit: bytes Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| InstallDate# | datetime | read | Date and time the object was installed. This property does not require a value to indicate that the object is installed. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LastErrorCode# | uint32 | read | Last error code reported by the logical device. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MaximumComponentLength# | uint32 | read | Maximum length of a filename component supported by the Windows drive. A filename component is that portion of a filename between backslashes. The value can be used to indicate that long names are supported by the specified file system. For example, for a FAT file system supporting long names, the function stores the value 255, rather than the previous 8.3 indicator. Long names can also be supported on systems that use the NTFS file system. Example: 255 Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MediaType# | uint32 | read | Type of media currently present in the logical drive. This value will be one of the values of the MEDIA_TYPE enumeration defined in Winioctl.h. The value may not be exact for removable drives if currently there is no media in the drive. Values (23)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Name# | string | read | Label by which the object is known. When subclassed, this property can be overridden to be a key property. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NumberOfBlocks# | uint64 | read | Total number of consecutive blocks, each block the size of the value contained in the BlockSize property, which form this storage extent. Total size of the storage extent can be calculated by multiplying the value of the BlockSize property by the value of this property. If the value of BlockSize is 1, this property is the total size of the storage extent. For more information about using uint64 values in scripts, see Scripting in WMI. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PNPDeviceID# | string | read | Windows Plug and Play device identifier of the logical device. Example: "*PNP030b" Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PowerManagementCapabilities# | uint16[] | read | Array of the specific power-related capabilities of a logical device. Values (8)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PowerManagementSupported# | boolean | read | If True, the device can be power-managed (can be put into suspend mode, and so on). This property does not indicate that power management features are currently enabled, only that the logical device is capable of power management. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ProviderName# | string | read | Network path to the logical device. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Purpose# | string | read | Free-form string describing the media and its use. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QuotasDisabled# | boolean | read | Indicates that quota management is not enabled (TRUE) on this system. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QuotasIncomplete# | boolean | read | Indicates that the quota management was used but has been disabled (True). Incomplete refers to the information left in the file system after quota management was disabled. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QuotasRebuilding# | boolean | read | If True, indicates that the file system is in the active process of compiling information and setting the disk up for quota management. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Size# | uint64 | read | Size of the disk drive. For a code example that retrieves this property, see the Remarks section, below. Unit: bytes Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Status# | string | read | Current status of the object. Various operational and nonoperational statuses can be defined. Operational statuses include: "OK", "Degraded", and "Pred Fail" (an element, such as a SMART-enabled hard disk drive, may be functioning properly but predicting a failure in the near future). Nonoperational statuses include: "Error", "Starting", "Stopping", and "Service". The latter, "Service", could apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is online, yet the managed element is neither "OK" nor in one of the other states. Values include the following: Values (12)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StatusInfo# | uint16 | read | State of the logical device. If this property does not apply to the logical device, the value 5 (Not Applicable) should be used. Values (5)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SupportsDiskQuotas# | boolean | read | If True, this volume supports disk quotas. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SupportsFileBasedCompression# | boolean | read | If True, the logical disk partition supports file-based compression, such as is the case with the NTFS file system. This property is False when the Compressed property is True. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SystemCreationClassName# key | string | read | Value of the scoping computer CreationClassName property. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SystemName# key | string | read | Name of the scoping system. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VolumeDirty# | boolean | read | If True, the disk requires ChkDsk to be run at the next restart. This property is only applicable to those instances of logical disk that represent a physical disk in the machine. It is not applicable to mapped logical drives. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VolumeName# | string | read/write | Volume name of the logical disk. Constraints: Maximum 32 characters. For a code example that retrieves this property, see the Remarks section, below. CodeWarning. Changes the system: check with -WhatIf first. An elevated console is often required. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VolumeSerialNumber# | string | read | Volume serial number of the logical disk. Constraints: Maximum 11 characters. Example: "A8C3-D032" Code |
Methods
Chkdsk #
Invokes the Chkdsk operation on the disk.
uint32 Chkdsk(
[in] boolean FixErrors,
[in] boolean VigorousIndexCheck,
[in] boolean SkipFolderCycle,
[in] boolean ForceDismount,
[in] boolean RecoverBadSectors,
[in] boolean OKToRunAtBootUp
);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| FixErrors | boolean | in | Indicates what should be done to errors found on the disk. If true, then errors are fixed. The default is false. |
| VigorousIndexCheck | boolean | in | If true, a less vigorous check of index entries should be performed. The default is false. |
| SkipFolderCycle | boolean | in | If true, the folder cycle checking should be skipped. The default is true. |
| ForceDismount | boolean | in | If true, the drive should be forced to dismount before checking. The default is false. |
| RecoverBadSectors | boolean | in | If true, the bad sectors should be located and the readable information should be recovered from these sectors. The default is false. |
| OKToRunAtBootUp | boolean | in | If true, the chkdsk operation should be performed at next boot up time, in case the operation could not be performed because the disk is locked at time this method is called. The default is false. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success - Chkdsk completed | |
| 1 | Success - Locked and chkdsk scheduled on reboot | |
| 2 | Failure - Unknown file system | |
| 3 | Failure - Unknown error | |
| 4 | Failure - Unsupported File System |
Call the Chkdsk method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID = 'C:'"
$methodParameters = @{
InputObject = $instance
MethodName = 'Chkdsk'
Arguments = @{
FixErrors = $false
VigorousIndexCheck = $false
SkipFolderCycle = $false
ForceDismount = $false
RecoverBadSectors = $false
OKToRunAtBootUp = $false
}
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$returnValueName = @{
0 = 'Success - Chkdsk completed'
1 = 'Success - Locked and chkdsk scheduled on reboot'
2 = 'Failure - Unknown file system'
3 = 'Failure - Unknown error'
4 = 'Failure - Unsupported File System'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
ExcludeFromAutochk #
Excludes disks from the Chkdsk operation to be run at the next restart.
uint32 ExcludeFromAutochk([in] string[] LogicalDisk);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| LogicalDisk | string[] | in | List of drives that should be excluded from autochk at the next reboot. The string syntax consists of the drive letter followed by a colon for the logical disk. Example: "C:" |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success | |
| 1 | Error - Remote Drive | |
| 2 | Error - Removable Drive | |
| 3 | Error - Drive Not Root Directory | |
| 4 | Error - Unknown Drive |
Call the ExcludeFromAutochk method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID = 'C:'"
$methodParameters = @{
InputObject = $instance
MethodName = 'ExcludeFromAutochk'
Arguments = @{ LogicalDisk = @('Example') }
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$returnValueName = @{
0 = 'Success'
1 = 'Error - Remote Drive'
2 = 'Error - Removable Drive'
3 = 'Error - Drive Not Root Directory'
4 = 'Error - Unknown Drive'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
ScheduleAutoChk #
Schedules Chkdsk to be run at the next restart if the dirty bit has been set.
uint32 ScheduleAutoChk([in] string[] LogicalDisk);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| LogicalDisk | string[] | in | Specifies the list of drives to schedule for Autochk at the next reboot. The string syntax consists of the drive letter followed by a colon for the logical disk, for example: "C:" Note: Always check the validity of the drive letters in the *LogicalDisk* array when the data comes from an unknown source, or a source that you do not trust. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | No Error | |
| 1 | Error - Remote Drive | |
| 2 | Error - Removable Drive | |
| 3 | Error - Drive Not Root Directory | |
| 4 | Error - Unknown Drive |
Call the ScheduleAutoChk method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID = 'C:'"
$methodParameters = @{
InputObject = $instance
MethodName = 'ScheduleAutoChk'
Arguments = @{ LogicalDisk = @('Example') }
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$returnValueName = @{
0 = 'No Error'
1 = 'Error - Remote Drive'
2 = 'Error - Removable Drive'
3 = 'Error - Drive Not Root Directory'
4 = 'Error - Unknown Drive'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Declared but not implemented methods: Reset, SetPowerState.
Remarks
The Win32_LogicalDisk class is derived from CIM_LogicalDisk which derives from CIM_StorageExtent. The CIM_StorageExtent class is derived from CIM_LogicalDevice.
A physical disk drive is the cornerstone of any storage management system. However, after a physical disk drive has been installed, neither users nor system administrators typically deal with the hardware directly. Instead, both users and system administrators interact with the logical drives that have been created on the disk.
A logical drive is a subdivision of a partition that has been assigned its own drive letter. (It is possible to have a partition that has not been assigned a drive letter.) When you talk about drive C or drive D, you are referring to a logical drive rather than to a physical disk drive. Likewise, when you save a document to drive E, you are saving it to the logical drive. Physical disks compose the hardware that makes up a drive, including such components as heads, sectors, and cylinders. Logical drives, by contrast, have properties such as disk space, available disk space, and drive letters.
Note: The Win32_LogicalDisk class can be used only to enumerate the properties of local disk drives. However, you can use the Win32_MappedLogicalDisk class to enumerate the properties of mapped network drives.
Inheritance
Superclass chain
- CIM_ManagedSystemElement
- CIM_LogicalElement
- CIM_LogicalDevice
- CIM_StorageExtent
- CIM_LogicalDisk
- Win32_LogicalDisk
Known subclasses
No known subclass.
Requirements
- Namespace
- root/cimv2
- Minimum client
- Windows Vista
- Minimum server
- Windows Server 2008
- Provider
- CIMWin32
- MOF file
- CIMWin32.mof
- DLL
- CIMWin32.dll
Class qualifiers
Dynamic Provider("CIMWin32") SupportsUpdate UUID("{8502C4B7-5FBB-11D2-AAC1-006008C78BC7}") AMENDMENT
Microsoft source
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.