PowerShell How to obtain a list of Windows users, user information _powershell

Source: Internet
Author: User

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:
Win32_UserAccount

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.