将所有本地成员和组一起显示 [英] Get All local members and groups displayed together

查看:122
本文介绍了将所有本地成员和组一起显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我有以下脚本,其作用类似于超级按钮,但仅列出了管理员组的成员。由于我的服务器可能是德语,法语……我无法保证这样的组将与英语单词一起存在。因此,我想对其进行调整以收集所有组和关联的成员,而不是仅收集管理员...………………………………………………

So far I have the below script that works like a charm but that only list the members of the group "Administrators". As my servers might be german, french ... I have no guarantee that such group will exist with the english word. So I want to adapt it to collect all groups and associated members instead of only Administrators... bummer I am stucked on a specific step

下面的脚本列出了所有在非空的本地组中。但是,我想在CSV中也输入用户所属的组的名称,以使解释更清楚。

The script below list all users that are in non-empty local groups. However I would like to get in my CSV also the name of the group the user is part of, for clearer interpretations.

有人可以帮我吗?

$Servers=Get-Content ListOfComputers.txt 
$output = 'ListOfLocalAdministratorsGroup.csv'
$results = @()

foreach($server in $Servers)
{
$admins = @()
$computer =[ADSI]"WinNT://$server"
$computer.psbase.children | where { $_.psbase.schemaClassName -eq 'group' } | foreach {
$group =[ADSI]$_.psbase.Path
$members = @($group.psbase.Invoke("Members"))
$members | foreach {
 $obj = new-object psobject -Property @{
 Server = $Server
 Admin = $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
 }
 $admins += $obj
 }}
$results += $admins
}
$results| Export-csv $Output -NoTypeInformation


推荐答案

本地管理员组将始终具有以下sid:S-1-5-32-544(在 Well- Windows操作系统中的已知安全标识符。

The local administrators group will always have the following sid: S-1-5-32-544 (documented at Well-known security identifiers in Windows operating systems.)

因此,您可以在脚本中添加以下内容以获得正确的组名:

So, you can add the following to your script to get the correct group name:

$objSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544")
$objgroup = $objSID.Translate( [System.Security.Principal.NTAccount])
$objgroupname = ($objgroup.Value).Split("\")[1]

这篇关于将所有本地成员和组一起显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆