Win32_UserAccount

Win32 User Account
root/cimv2dynamic

The Win32_UserAccount WMI class contains information about a user account on a computer system running Windows.

On this page

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, SID

Examples

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, SID

The 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, SID

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_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, ReturnType

Properties

16 of 16 properties
NameTypeAccessDescription
AccountTypeuint32read

Flags that describe the characteristics of a Windows user account.

Values (5)
ValueLabelDescription
256Temporary duplicate account**UF_TEMP_DUPLICATE_ACCOUNT** Local user account for users who have a primary account in another domain. This account provides user access to this domain only—not to any domain that trusts this domain.
512Normal account**UF_NORMAL_ACCOUNT** Default account type that represents a typical user.
2048Interdomain trust account**UF_INTERDOMAIN_TRUST_ACCOUNT** Account for a system domain that trusts other domains.
4096Workstation trust account**UF_WORKSTATION_TRUST_ACCOUNT** Computer account for a computer system running Windows that is a member of this domain.
8192Server trust account**UF_SERVER_TRUST_ACCOUNT** Account for a system backup domain controller that is a member of this domain.
Code
# Value of AccountType for each instance
# 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'
}
Get-CimInstance -ClassName Win32_UserAccount -Property Name, AccountType |
    Select-Object -Property @(
        'Name'
        @{ Name = 'AccountType'; Expression = { $accountTypeName[[int]$_.AccountType] } }
    )
Captionstringread

Domain and username of the account.

Code
# Value of Caption for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name, Caption |
    Select-Object -Property Name, Caption
Descriptionstringread

Description of the account.

Code
# Value of Description for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name, Description |
    Select-Object -Property Name, Description
Disabledbooleanread/write

Windows user account is disabled.

Code
# Value of Disabled for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name, Disabled |
    Select-Object -Property Name, Disabled

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

# Warning: changes Disabled on the instance. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_UserAccount |
    Select-Object -First 1
$setParameters = @{
    InputObject = $instance
    Property    = @{ Disabled = $false }
    WhatIf      = $true  # Remove this line to actually apply the change
}
Set-CimInstance @setParameters
Domainstringread

Name of the Windows domain to which a user account belongs, for example: "NA-SALES".

Code
# Value of Domain for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name, Domain |
    Select-Object -Property Name, Domain
FullNamestringread/write

Full name of a local user, for example: "Dan Wilson".

Code
# Value of FullName for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name, FullName |
    Select-Object -Property Name, FullName

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

# Warning: changes FullName on the instance. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_UserAccount |
    Select-Object -First 1
$setParameters = @{
    InputObject = $instance
    Property    = @{ FullName = 'Example' }
    WhatIf      = $true  # Remove this line to actually apply the change
}
Set-CimInstance @setParameters
InstallDatedatetimeread

Date the object is installed. This property does not need a value to indicate that the object is installed.

Code
# Value of InstallDate for each instance
# CIM cmdlets already return a DateTime object: no conversion is needed
Get-CimInstance -ClassName Win32_UserAccount -Property Name, InstallDate |
    Select-Object -Property Name, InstallDate
LocalAccountbooleanread

If true, the account is defined on the local computer.

Code
# Value of LocalAccount for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name, LocalAccount |
    Select-Object -Property Name, LocalAccount
Lockoutbooleanread/write

If true, the user account is locked out of the Windows operating system.

Code
# Value of Lockout for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name, Lockout |
    Select-Object -Property Name, Lockout

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

# Warning: changes Lockout on the instance. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_UserAccount |
    Select-Object -First 1
$setParameters = @{
    InputObject = $instance
    Property    = @{ Lockout = $false }
    WhatIf      = $true  # Remove this line to actually apply the change
}
Set-CimInstance @setParameters
Namestringread

Name of the Windows user account on the domain that the Domain property of this class specifies.

Example: "danwilson".

Code
# Value of Name for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name |
    Select-Object -Property Name
PasswordChangeablebooleanread/write

If true, the password on this user account can be changed.

Code
# Value of PasswordChangeable for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name, PasswordChangeable |
    Select-Object -Property Name, PasswordChangeable

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

# Warning: changes PasswordChangeable on the instance. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_UserAccount |
    Select-Object -First 1
$setParameters = @{
    InputObject = $instance
    Property    = @{ PasswordChangeable = $false }
    WhatIf      = $true  # Remove this line to actually apply the change
}
Set-CimInstance @setParameters
PasswordExpiresbooleanread/write

If true, the password on this user account expires.

Code
# Value of PasswordExpires for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name, PasswordExpires |
    Select-Object -Property Name, PasswordExpires

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

# Warning: changes PasswordExpires on the instance. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_UserAccount |
    Select-Object -First 1
$setParameters = @{
    InputObject = $instance
    Property    = @{ PasswordExpires = $false }
    WhatIf      = $true  # Remove this line to actually apply the change
}
Set-CimInstance @setParameters
PasswordRequiredbooleanread/write

If true, a password is required on a Windows user account. If false, this account does not require a password.

Code
# Value of PasswordRequired for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name, PasswordRequired |
    Select-Object -Property Name, PasswordRequired

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

# Warning: changes PasswordRequired on the instance. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_UserAccount |
    Select-Object -First 1
$setParameters = @{
    InputObject = $instance
    Property    = @{ PasswordRequired = $false }
    WhatIf      = $true  # Remove this line to actually apply the change
}
Set-CimInstance @setParameters
SIDstringread

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
# Value of SID for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name, SID |
    Select-Object -Property Name, SID
SIDTypeuint8read

Enumerated value that specifies the type of SID.

Values (9)
ValueLabelDescription
1SidTypeUser
2SidTypeGroup
3SidTypeDomain
4SidTypeAlias
5SidTypeWellKnownGroup
6SidTypeDeletedAccount
7SidTypeInvalid
8SidTypeUnknown
9SidTypeComputer
Code
# Value of SIDType for each instance
# 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 -Property Name, SIDType |
    Select-Object -Property @(
        'Name'
        @{ Name = 'SIDType'; Expression = { $sIDTypeName[[int]$_.SIDType] } }
    )
Statusstringread

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)
ValueLabelDescription
OKOK
ErrorError
DegradedDegraded
UnknownUnknown
Pred FailPred Fail
StartingStarting
StoppingStopping
ServiceService
StressedStressed
NonRecoverNonRecover
No ContactNo Contact
Lost CommLost Comm
Code
# Value of Status for each instance
Get-CimInstance -ClassName Win32_UserAccount -Property Name, Status |
    Select-Object -Property Name, Status

Methods

Rename #

Allows for the renaming of the user account.

uint32 Rename([in] string Name);

Parameters

ParameterTypeDirectionDescription
Namestringin

New account name.

Return values

ValueLabelDescription
0Success
1Instance not found
2Instance required
3Invalid parameter
4User not found
5Domain not found
6Operation is allowed only on the primary domain controller of the domain
7Operation is not allowed on the last administrative account.
8Operation 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.
9Other API error
10Internal 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

  1. CIM_ManagedSystemElement
  2. CIM_LogicalElement
  3. Win32_Account
  4. 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

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.