powershell - 列出递归授予特定用户的 AD 组?
问题描述
我想检查特定用户帐户或管理员组的递归 AD 组成员身份并对其进行故障排除。
这里的目标是知道哪个 AD 组被多次递归地授予脚本中的用户输入。
Param
(
[string]$user = 'IT.Support'
)
Function Get-ADPrincipalGroupMembershipRecursive([Parameter(ValueFromPipeline = $true)]$Identity)
{
Process
{
$object = Get-ADObject -Identity $Identity -Property memberOf, primaryGroupID, objectSid
If ($object.objectClass -eq 'group')
{
Get-ADGroup -Identity $object -Property memberOf
}
Else
{
[void]$object.memberof.Add((Get-ADGroup -Identity ($object.objectSid -replace '^(.*?-)([0-9]+)$', ('${1}' + $object.primaryGroupID))).DistinguishedName)
}
$object.memberOf | Get-ADPrincipalGroupMembershipRecursive
}
}
Function Get-CanonicalName ([string[]]$DistinguishedName)
{
foreach ($dn in $DistinguishedName)
{
$d = $dn.Split(',')
$arr = (@(($d | Where-Object { $_ -notmatch 'DC=' }) | ForEach-Object { $_.Substring(3) }))
[array]::Reverse($arr)
"{0}/{1}" -f (($d | Where-Object { $_ -match 'dc=' } | ForEach-Object { $_.Replace('DC=', '') }) -join '.'), ($arr -join '/')
}
}
Get-ADUser -Identity $user |
Get-ADPrincipalGroupMembershipRecursive |
Sort-Object Name |
Select Name, `
GroupCategory, `
GroupScope, `
@{ N = 'OU Location'; E = { Get-CanonicalName $_.DistinguishedName } },
@{ N = 'Parent(s)'; E = { $r = Foreach ($m in $_.memberof) { Get-CanonicalName $m }; $r -join ',' } } |
Out-GridView
但是,上面的脚本没有显示哪些 AD 组在另一个 AD 组中被多次递归地授予IT.Support用户。
例如: 输入:IT.Support 所需或例外的输出是:
Name, GroupCategory, GroupScope, OU Location, Parent (s)
Domain Admins, Security, Universal, domain.com/Production, <Direct membership>
M365 Global Admin, Security, Universal, domain.com/Production, Domain Admins
Regional1 Global Admin, Security, Universal, domain.com/Production, M365 Global Admin
Regional2 Global Admin, Security, Universal, domain.com/Production, M365 Global Admin
用户 IT.Support 是 Domain Admins 内置组的直接成员。
Group M365 Global Admin 嵌套在 Domain Admins 组下。Regional1 Global Admin 和 Regional2 Global Admin 组嵌套在 M365 Global Admin 下
因此,我知道会员路径或递归他们从哪里获得会员资格
解决方案
推荐阅读
- python - 使用 Seaborn 绘制条形图
- powerbi - Power BI 查询按顺序运行
- javascript - NODE.JS - 检查对象中是否有意外字段
- html - 动画后接收指针事件的链接在 Safari 中不可点击
- javascript - 访问从服务器端(Node.js)的 Swift 客户端发送的 HTTP 请求的正文?
- java - spring 从 xml 文件中获取 bean 时出错
- php - 我正在尝试从客户默认来源获取卡号的最后 4 位数字
- java - 如何通过他们实现的接口找到实例?
- python-3.x - 在 Python 中获取 Windows 计量连接状态
- functional-programming - OCaml 错误:评估期间的堆栈溢出(循环递归?)