如何使用 PowerShell 获取本地用户帐户
在 PowerShell 中使用 `Get-LocalUser` 命令获取本地用户帐户。此命令获取默认的内置用户帐户、您创建的本地用户帐户以及连接到 Microsoft 帐户的本地帐户。
以下是获取本地用户帐户的 PowerShell 脚本。
Get-LocalUser在本文中,我们将讨论如何获取所有本地用户帐户、通过名称获取本地用户帐户、获取具有指定 SID 的用户帐户。
如何使用 PowerShell 获取本地用户帐户
使用 PowerShell 获取本地用户帐户的命令是 Get-LocalUser。此命令获取所有本地用户帐户和内置用户帐户。
Get-LocalUser上述 PowerShell 脚本的输出返回计算机上所有本地用户帐户的列表。
PS C:\> Get-LocalUser
Name Enabled Description
---- ------- -----------
admin True Built-in account for administering the computer/domain
Guest False Built-in account for guest access to the computer/domain
krbtgt False Key Distribution Center Service Account
toms True
ErickJ True
garyw True
chrisd True
adam True
nathan False
Don True如何在 PowerShell 中使用本地用户帐户名称获取本地用户帐户
使用带有 Name 参数的 Get-LocalUser 命令指定用户名以获取本地用户帐户。
Get-LocalUser -Name Arons在上面的 PowerShell 脚本中,Get-LocalUser 命令使用 Name 参数指定本地用户帐户名称并获取其帐户,其中包括名称、已启用和说明。
下面给出了上述用于获取本地用户帐户的 PowerShell 脚本的输出。
如何获取具有特定 SID 的本地用户帐户
使用 Get-LocalUser cmdlet 获取本地用户帐户,它使用 SID 属性指定用户 SID 并返回本地用户帐户。
Get-LocalUser -SID S-1-5-21-1326752099-4012446882-462961959-2601上述 PowerShell 脚本的输出获取具有指定 SID 的本地用户帐户。
PS C:\> Get-LocalUser -SID S-1-5-21-1326752099-4012446882-462961959-2601
Name Enabled Description
---- ------- -----------
garyw True
结论
希望上面关于如何使用PowerShell Get-LocalUser命令获取本地用户帐户的文章对您有所帮助。
您可以在 ShellGeek 主页上找到有关 PowerShell Active Directory 命令和 PowerShell 基础知识的更多主题。
相关链接
Microsoft.PowerShell.LocalAccounts 模块
添加本地组成员
获取本地组成员
新本地用户
启用本地用户
禁用本地用户
重命名-本地用户
设置本地用户
