如何将安全组的安全成员列表导出到 Excel 表。我在网上找到了一些代码,但我需要一个可以执行此操作的 UI 或软件。
我对 Powershell 持开放态度......
问候,
D.
答案1
数值模拟与数值模拟将会按照您的要求执行。
答案2
下面是我用来通过 powershell 获取用户信息并将其放入 excel 电子表格的用户信息脚本的快速破解版:
请注意,我还没有测试过这些修改,而且它们需要一些工作才能同时处理多个组
#Make ADSI Connection
$Group = [ADSI]"LDAP://<domain>/<ldap_cn_of_group"
#Setup our excel File
$Excel = new-object -comobject Excel.Application
$Workbook = $Excel.workbooks.add()
$Worksheet = $Workbook.worksheets.item(1)
# Setup a counter for our rows(Start at 2 0 wich is cell A2, the header stuff goes at 1,0 which is A1)
$Row = 2
#Create File and Header information
#sc -path ADUIout.txt -value "Group,Membership"
$Worksheet.cells.item(1,1) = "Group"
$Worksheet.cells.item(1,4) = "Group Membership"
#$Excel.visible = $TRUE
$membership = $null
foreach ($member in $Group.member)
{
$Worksheet.cells.item($Row, 1) = "$Group"
$Worksheet.cells.item($Row, 2) = "$member"
$Row++
}
$Workbook.saveas("H:\ADUI.xls")
$Workbookl.save()
$Excel.quit()
以下是原始脚本,以防有人想看,或者想了解其中的一些概念:
#Active Directory User information script
#Make ADSI Connection
$AD_Top = [ADSI]"LDAP://<domain>/<base_LDAP_String>"
#Setup our excel File
$Excel = new-object -comobject Excel.Application
$Workbook = $Excel.workbooks.add()
$Worksheet = $Workbook.worksheets.item(1)
# Setup a counter for our rows(Start at 2 0 wich is cell A2, the header stuff goes at 1,0 which is A1)
$Row = 2
#Create File and Header information
#sc -path ADUIout.txt -value "User Name,Container,Last Logon, Logon Count, Group membership"
$Worksheet.cells.item(1,1) = "User Name"
$Worksheet.cells.item(1,2) = "Container"
$Worksheet.cells.item(1,3) = "Last Logon Count"
$Worksheet.cells.item(1,4) = "Group Membership"
#$Excel.visible = $TRUE
#Create the Header
foreach ($Container in $AD_Top.psBase.children)
{
if(($Container.psBase.properties.name -notmatch "Computers") -AND ($Container.psBase.properties.name -notmatch "Servers") `
-AND ($Container.psBase.properties.name -notmatch "Domain Controllers") `
-AND ($Container.psBase.properties.name -notmatch "EmailDistribution") `
-AND ($Container.psBase.properties.name -notmatch "Security Groups") `
-AND ($Container.psBase.properties.name -notmatch "Microsoft Exchange System Objects") `
-AND ($Container.psBase.properties.name -notmatch "System") `
-AND ($Container.psBase.properties.name -notmatch "ForeignSecurityPrincipals"))
{
$outputCont = $Container.psBase.properties.name
foreach ($user in $Container.psBase.children)
{
$dirSearch = new-object directoryservices.directorysearcher($user)
$LastLogon = [datetime]::fromfiletime(($DirSearch.findone().properties.lastlogon)[0])
$Username = $User.cn
$LogonCount = $User.logoncount
$membership = $null
foreach ($group in $user.memberof)
{
$membership = $membership + $group.substring(3).Remove($group.substring(3).indexOf(",")) + "`n"
}
#$output = "$Username,$outputCont,$LastLogon,$logonCount,$membership"
$Worksheet.cells.item($Row, 1) = "$Username"
$Worksheet.cells.item($Row, 2) = "$outputCont"
$Worksheet.cells.item($Row, 3) = $LastLogon
$Worksheet.cells.item($Row, 4) = $membership
#ac -path ADUIout.txt -value $output
$Row++
}
}
}
$Workbook.saveas("H:\ADUI.xls")
$Workbookl.save()
$Excel.quit()