powershell - 列出本地用户及其组
我想要一份包含所有本地用户及其相关组(用户、高级用户、管理员等)的报告。
我以这种方式获取用户:
$adsi = [ADSI]"WinNT://."
$adsi.psbase.children | where {$_.psbase.schemaClassName -match "user"} | select @{n="Name";e={$_.name}}
但我不知道如何检索他们的组。谢谢进步。
I'd like to have a report with all the local users and their relative groups (users, power users, administrators and so on.
I get the users in this way:
$adsi = [ADSI]"WinNT://."
$adsi.psbase.children | where {$_.psbase.schemaClassName -match "user"} | select @{n="Name";e={$_.name}}
but I don't know how to retrieve their groups. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对于 Google 员工来说,获取用户列表的另一种方法是使用:
来自 http://buckeyejeeps.com/blog/?p=第764章
For Googlers, another way to get a list of users is to use:
From http://buckeyejeeps.com/blog/?p=764
更新为 2010 年优秀答案的替代方案:
您现在可以使用
Get-LocalGroupMember
、Get-LocalGroup
、Get- LocalUser
等来自Microsoft。 PowerShell.LocalAccounts
模块,用于获取和映射用户和组,适用于 PowerShell 5.1 及更高版本。示例:
您可以将其与
Get-LocalUser
结合起来。也可以使用别名glu
来代替。大多数新 cmdlet 都存在别名。如果有人想知道(我知道你没有问过这个)
添加用户可以像这样完成:
Update as an alternative to the excellent answer from 2010:
You can now use the
Get-LocalGroupMember
,Get-LocalGroup
,Get-LocalUser
etc. from theMicrosoft.PowerShell.LocalAccounts
module to get and map users and groups, available in PowerShell 5.1 and above.Example:
You could combine that with
Get-LocalUser
. Aliasglu
can also be used instead. Aliases exists for the majority of the new cmdlets.In case some are wondering (I know you didn't ask about this)
Adding users could be for example done like so:
使用它来获取包含本地用户及其所属组的数组:
要获取包含本地组及其成员的数组:
Use this to get an array with the local users and the groups they are member of:
To get an array with the local groups and their members:
扩展 mjswensen 的答案,没有过滤器的命令可能需要几分钟,但过滤后的命令几乎是即时的。
PowerShell - 列出本地用户帐户
快速方式
慢速方式
Expanding on mjswensen's answer, the command without the filter could take minutes, but the filtered command is almost instant.
PowerShell - List local user accounts
Fast way
Slow way
试试这个:),
try this one :),