Main example
List instances
# All instances of Win32_UserAccount, with the main properties
Get-CimInstance -ClassName Win32_UserAccount |
Select-Object -Property Name, Caption, Description, Status, InstallDate, Domain, SIDExamples
Filter with WQL
# WQL filter evaluated by the provider: AccountType = 512 (Normal account)
Get-CimInstance -ClassName Win32_UserAccount -Filter 'AccountType = 512' |
Select-Object -Property Name, Caption, Description, Status, InstallDate, Domain, SIDThe filter is evaluated by the WMI provider: less data is transferred than with Where-Object.
Decode numeric values
# Lookup table for AccountType (values documented by Microsoft)
$accountTypeName = @{
256 = 'Temporary duplicate account'
512 = 'Normal account'
2048 = 'Interdomain trust account'
4096 = 'Workstation trust account'
8192 = 'Server trust account'
}
# Lookup table for SIDType (values documented by Microsoft)
$sIDTypeName = @{
1 = 'SidTypeUser'
2 = 'SidTypeGroup'
3 = 'SidTypeDomain'
4 = 'SidTypeAlias'
5 = 'SidTypeWellKnownGroup'
6 = 'SidTypeDeletedAccount'
7 = 'SidTypeInvalid'
8 = 'SidTypeUnknown'
9 = 'SidTypeComputer'
}
Get-CimInstance -ClassName Win32_UserAccount |
Select-Object -Property Name, Caption, Description, Status, InstallDate, Domain, SIDQuery 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_UserAccount |
Select-Object -Property Name, Caption, Description, Status, InstallDate, Domain, SID
} 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_UserAccount
$cimClass.CimClassProperties |
Select-Object -Property Name, CimType, Flags
# Methods of the class
$cimClass.CimClassMethods |
Select-Object -Property Name, ReturnTypeProperties
| Name | Type | Access | Description | |||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| AccountType# | uint32 | read | Flags that describe the characteristics of a Windows user account. Values (5)
Code | |||||||||||||||||||||||||||||||||||||||
| Caption# | string | read | Domain and username of the account. Code | |||||||||||||||||||||||||||||||||||||||
| Description# | string | read | Description of the account. Code | |||||||||||||||||||||||||||||||||||||||
| Disabled# | boolean | read/write | Windows user account is disabled. CodeWarning. Changes the system: check with -WhatIf first. An elevated console is often required. | |||||||||||||||||||||||||||||||||||||||
| Domain# | string | read | Name of the Windows domain to which a user account belongs, for example: "NA-SALES". Code | |||||||||||||||||||||||||||||||||||||||
| FullName# | string | read/write | Full name of a local user, for example: "Dan Wilson". CodeWarning. Changes the system: check with -WhatIf first. An elevated console is often required. | |||||||||||||||||||||||||||||||||||||||
| InstallDate# | datetime | read | Date the object is installed. This property does not need a value to indicate that the object is installed. Code | |||||||||||||||||||||||||||||||||||||||
| LocalAccount# | boolean | read | If true, the account is defined on the local computer. Code | |||||||||||||||||||||||||||||||||||||||
| Lockout# | boolean | read/write | If true, the user account is locked out of the Windows operating system. CodeWarning. Changes the system: check with -WhatIf first. An elevated console is often required. | |||||||||||||||||||||||||||||||||||||||
| Name# | string | read | Name of the Windows user account on the domain that the Domain property of this class specifies. Example: "danwilson". Code | |||||||||||||||||||||||||||||||||||||||
| PasswordChangeable# | boolean | read/write | If true, the password on this user account can be changed. CodeWarning. Changes the system: check with -WhatIf first. An elevated console is often required. | |||||||||||||||||||||||||||||||||||||||
| PasswordExpires# | boolean | read/write | If true, the password on this user account expires. CodeWarning. Changes the system: check with -WhatIf first. An elevated console is often required. | |||||||||||||||||||||||||||||||||||||||
| PasswordRequired# | boolean | read/write | If true, a password is required on a Windows user account. If false, this account does not require a password. CodeWarning. Changes the system: check with -WhatIf first. An elevated console is often required. | |||||||||||||||||||||||||||||||||||||||
| SID# | string | read | Security identifier (SID) for this account. A SID is a string value of variable length that is used to identify a trustee. Each account has a unique SID that an authority, such as a Windows domain, issues. The SID is stored in the security database. When a user logs on, the system retrieves the user SID from the database, places the SID in the user access token, and then uses the SID in the user access token to identify the user in all subsequent interactions with Windows security. Each SID is a unique identifier for a user or group, and a different user or group cannot have the same SID. Code | |||||||||||||||||||||||||||||||||||||||
| SIDType# | uint8 | read | Enumerated value that specifies the type of SID. Values (9)
Code | |||||||||||||||||||||||||||||||||||||||
| Status# | string | read | Current status of an object. Various operational and nonoperational statuses can be defined. Operational statuses include: "OK", "Degraded", and "Pred Fail", which is an element such as a SMART-enabled hard disk drive that may be functioning properly, but predicts a failure in the near future. Nonoperational statuses include: "Error", "Starting", "Stopping", and "Service", which can apply during mirror resilvering of a disk, reloading a user permissions list, or other administrative work. Values include the following: Values (12)
Code |
Methods
Rename #
Allows for the renaming of the user account.
uint32 Rename([in] string Name);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| Name | string | in | New account name. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success | |
| 1 | Instance not found | |
| 2 | Instance required | |
| 3 | Invalid parameter | |
| 4 | User not found | |
| 5 | Domain not found | |
| 6 | Operation is allowed only on the primary domain controller of the domain | |
| 7 | Operation is not allowed on the last administrative account. | |
| 8 | Operation is not allowed on specified special groups; user, admin, local or guest. | Operation is not allowed on specified special groups: user, admin, local, or guest. |
| 9 | Other API error | |
| 10 | Internal error |
Call the Rename 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_UserAccount
$methodParameters = @{
InputObject = $instance
MethodName = 'Rename'
Arguments = @{ Name = '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 = 'Instance not found'
2 = 'Instance required'
3 = 'Invalid parameter'
4 = 'User not found'
5 = 'Domain not found'
6 = 'Operation is allowed only on the primary domain controller…'
7 = 'Operation is not allowed on the last administrative account'
8 = 'Operation is not allowed on specified special groups; user,…'
9 = 'Other API error'
10 = 'Internal error'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Remarks
The Win32_UserAccount class is derived from Win32_Account.
Note: An error is not returned for an attempt to write to a read-only property, and the value of the property remains unchanged.
Inheritance
Superclass chain
- CIM_ManagedSystemElement
- CIM_LogicalElement
- Win32_Account
- Win32_UserAccount
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") UUID("{8502C4CC-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.