PowerShell获取Windows用户列表、用户信息的方法

2019-09-30 16:06:47丽君

SID                : S-1-5-21-181061805-855091228-1216038997-1000
SIDType            : 1
Scope              : System.Management.ManagementScope
Path               : HONG-BOOKrootcimv2:Win32_UserAccount.Domain="hong-book",Name="hong"
Options            : System.Management.ObjectGetOptions
ClassPath          : HONG-BOOKrootcimv2:Win32_UserAccount
Properties         : {AccountType, Caption, Description, Disabled...}
SystemProperties   : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...}
Qualifiers         : {dynamic, Locale, provider, UUID}
Site               :
Container          :

利用对象提供的这些属性信息,我们可以做很多事情,比如我们想看看当前小编登录的账号的密码是否已过期,则可以写这样一个函数:

function Test-UserPasswordExpires
{
param(
     $UserName = $env:username,
     $Domain = $env:userdomain
   )

    (Get-WmiObject -Class Win32_UserAccount -Filter "Name='$UserName' and Domain='$Domain'").PasswordExpires
}

好了,关于用户信息差不多就这么多,小编祝大家使用愉快!