基本上,在我们的环境中,我们有大量的安全组。嵌套其他团体等内的所以这是一个真正的PITA找出为什么设置应用到用户安全组,因为嵌套的群体之一,他们可能会或可能不会是通过嵌套AD组查找用户和AD组关系
对于例如一部分如果您将用户添加到X组,他们突然在Citrix中拥有已发布的应用程序。 Citrix为安全组Y配置。尝试查找X和Y之间的链接非常耗时,但可以自动化。
我想创建一个脚本,在其中输入用户和最终安全组(上面的组Y),并且脚本输出将用户连接到最终组的中间组。如果这是有道理的?
事情是这样的:
function get-grouprelationship($username, $knownsecuritygroup)
{
$getallgroups = get-adgroupmember $knownsecuritygroup | where-object {$_.ObjectClass -eq "Group" | select-object SamAccountName | foreach-object {get-adgroupmember $_.SamAccountName}
}
(以上变量取你的团队,并通过该组的所有成员循环,打印他们的成员)
$usergroups = (get-aduser -identity $username -Properties memberof | select-object memberof).memberof
(以上得到的所有组用户在)
$usergroups1 = $usergroups.split(",")
$usergroups2 = $usergroups1[0]
$usergroups3 = $usergroups2.substring(3)
(以上格式文本很好)
if ($usergroups3 -contains $groupname){write-host "$username is directly in $groupname}
从这里,我很坚持,因为我基本上需要嵌套多个for循环,取决于有多少组各小组。然后做健康检查是
if ($groupname -eq $currentgroup){write-host "connected by $groupname and $currentgroup}
我也坚持与$getallgroups
变量,因为它只检查1个水平下降。然后它会需要另一个foreach
循环里面,这将需要另一个在那里等
没有先前的编码经验,我真的很难找到一个简单的方法来实现我的目标。
编辑:
我发现这里这个脚本 - script。下面基本的工作原理,但它实在是太大了详细:
import-module activedirectory
$username = read-host "What's their username?"
Function RecurseUsersInGroup {
Param ([string]$object = "", [int]$level = 0)
$indent = "-" * $level
$x = Get-ADObject -Identity $object -Properties SamAccountName
if ($x.ObjectClass -eq "group") {
Write-Host "# $($x.SamAccountName)"
$y = Get-ADGroup -Identity $object -Properties Members
$y.Members | %{
$o = Get-ADObject -Identity $_ -Properties SamAccountName
if ($o.ObjectClass -eq "user" -and $o.SamAccountName -eq $username) {
Write-Host "-> $($o.SamAccountName)"
} elseif ($o.ObjectClass -eq "group") {
RecurseUsersInGroup $o.DistinguishedName ($level + 1)
}
}
} else {
Write-Host "$($object) is not a group, it is a $($x.ObjectClass)"
}
}
$thegroup = read-host "What's the Group?"
RecurseUsersInGroup (get-adgroup $thegroup).DistinguishedName
这工作正常,但似乎每一个输出安全组,反对连接的。当然,朝着正确的方向迈出一步!如果我找到源,我也会发布信用。
我编辑了我的上面的帖子,基本上需要一些触摸的解决方案! – user3317623