WMI is the abbreviation for Windows Management specification, which contains a lot of system hardware and software information. Windows user information can also be obtained through WMI objects. PowerShell provides access to WMI, very handy and powerful-this is the cmdlet get-wmiobject.
Get a list of all Windows users:
Get-wmiobject-class Win32_UserAccount or Get-wmiobject.
Copy Code code as follows:
If you want to see the information for the currently logged-on user, you can use the following statement:
Copy Code code as follows:
Get-wmiobject-class win32_useraccount-filter "Name= ' $env: Username ' and domain= ' $env: UserDomain '"
Where $env:username represents the user name that is currently logged on to the system, and $env:userdomain represents the domain (or machine name) of the current user.
The above statement in fact only shows the user's basic information, if you want to see more detailed information, you can find out the user as an object, using the Select-object method to view all of its information.
Copy Code code as follows:
Get-wmiobject-class win32_useraccount-filter "Name= ' $env: Username ' and domain= ' $env: UserDomain '" | Select-object *
The information you get will look like this:
Copy Code code as follows:
Status:ok
Caption:hong-book\hong
Passwordexpires:false
__genus:2
__class:win32_useraccount
__superclass:win32_account
__dynasty:cim_managedsystemelement
__relpath:win32_useraccount.domain= "Hong-book", name= "the"
__property_count:16
__derivation: {win32_account, cim_logicalelement, cim_managedsystemelement}
__server:hong-book
__namespace:root\cimv2
__path: \\hong-book\root\cimv2:win32_useraccount.domain= "Hong-book", name= "the"
accounttype:512
Description:
Disabled:false
Domain:hong-book
FullName:
InstallDate:
Localaccount:true
Lockout:false
Name:hong
Passwordchangeable:true
Passwordrequired:false
sid:s-1-5-21-181061805-855091228-1216038997-1000
Sidtype:1
Scope:System.Management.ManagementScope
Path: \\hong-book\root\cimv2:win32_useraccount.domain= "Hong-book", name= "the"
Options:System.Management.ObjectGetOptions
ClassPath: \\hong-book\root\cimv2:win32_useraccount
Properties: {accounttype, Caption, Description, Disabled ...}
Systemproperties: {__genus, __class, __superclass, __dynasty ...}
Qualifiers: {dynamic, Locale, provider, UUID}
Site:
Container:
We can do a lot of things by using the attribute information provided by the object, for example, if we want to see whether the password of the current small-numbered login account has expired, you can write a function like this:
Copy Code code as follows:
function Test-userpasswordexpires
{
Param
$UserName = $env: UserName,
$Domain = $env: UserDomain
)
(Get-wmiobject-class win32_useraccount-filter "Name= ' $UserName ' and domain= ' $Domain"). Passwordexpires
}
Well, about the user information about so much, small weave wish everyone to use happy!