powershell - 列出本地用户及其组 [英] powershell - list local users and their groups
本文介绍了powershell - 列出本地用户及其组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一份关于所有本地用户及其相关组(用户、高级用户、管理员等)的报告.
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.
推荐答案
$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
$adsi.Children | where {$_.SchemaClassName -eq 'user'} | Foreach-Object {
$groups = $_.Groups() | Foreach-Object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
$_ | Select-Object @{n='UserName';e={$_.Name}},@{n='Groups';e={$groups -join ';'}}
}
这篇关于powershell - 列出本地用户及其组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文