繁体   English   中英

Powershell Active Directory 中的访问列表

[英]Powershell access lists in Active Directory

当我在同一次运行中创建 object $ouUnixGroups时,我有一个 function GrantGenericRead可以工作。 我试图弄清楚如何从我可以运行GrantGenericRead的 AD 中获取 object,但似乎当我以各种方式尝试时我知道如何(adsi,查找使用.Path),我无法访问某些属性的 object 来设置它。 我很想有人告诉我我做错了什么。

此代码在同时运行时有效:

function CreateADGroup([string] $server, [string] $name, [string] $container, [string] $gtype)
{
    $objClass = "group";
    $strCn = GetCn -name $name -objClass $objClass;
    $objDsGroup  = CreateDsObject -server $server -container $container -name $name -objClass $objClass 
    [Void] $objDsGroup.Put("sAMAccountName", $name)
    if ($gtype -eq "global")
    {
        # Global Distribution Group 
        [Void] $objDsGroup.Put("groupType", 0x80000002)
    }
    elseif ($gtype -eq "dlg")
    {
        # Domain Local Distribution Group  
        [Void] $objDsGroup.Put("groupType", 0x80000004)
    }
    elseif ($gtype -eq "uni")
    {
        # Universal Security Group 
        [Void] $objDsGroup.Put("groupType", 0x80000008)
    }
    else
    {
        Write-Host("Invalid group type {0}" -f $gtype)
    }
    [Void]$objDsGroup.SetInfo()
    return $objDsGroup
}

function CreateDsObject([string] $server, [string] $container, [string] $name, [string] $objClass)
{
$strConatinerPath = GetLdapPath -server $server -dn $container
$objContainer = [adsi] $strConatinerPath
$strChildCn = GetCn -name $name -objClass $objClass
$strChildDn = "{0},{1}" -f $strChildCn, $container
$strChildPath = GetLdapPath -server $server -dn $strChildDn
$objChildEntry = $objContainer.Create($objClass, $strChildCn)
[Void]$objChildEntry.SetInfo()
    return $objChildEntry
}

function GrantGenericRead($dsTrustee, $dsResources)
{
    $strSid = GetSid -dsObj $dsTrustee
    $objSid = New-Object Security.Principal.SecurityIdentifier($strSid)
    $ace = New-Object DirectoryServices.ActiveDirectoryAccessRule($objSid, $AD_RIGHT::GenericRead, $AC_TYPE::Allow)
    [Void] $dsResources.psbase.ObjectSecurity.AddAccessRule($ace)
    [Void] $dsResources.psbase.CommitChanges()
}

function GetSid($dsObj)
{
    $dn = $dsObj.distinguishedName.Value
    $binary = $dsObj.psbase.Properties["objectSid"].Value
    $sid = New-Object Security.Principal.SecurityIdentifier($binary, 0)
    return $sid.ToString()
}

$adminContainerDn = "OU=Zone Administration,{0}" -f   $adminContainer.Get("distinguishedName") #returns OU=Zone Administration,OU=asdfasdf,DC=baldur,DC=vm
$ouUnixGroups   = CreateDsObject -server $server -container $ouDN -name $strOuUnixGroups   -objClass "OrganizationalUnit"
$joinOps = CreateADGroup -server $server -name "Join Operators" -container $adminContainerDn -gtype "global"

GrantGenericRead -dsTrustee $joinOps -dsResources $ouUnixGroups

我想要完成的是能够从不创建它们的脚本中修改$joinOps$ouUnixGroups 我如何访问它们? 我可以获得 sid,但这似乎对我没有帮助,除非我在这里遗漏了一些非常关键的东西。

GrantGenericRead -dsTrustee $joinOps -dsResources [adsi]$ouUnixGroups.Path

如果有人想看一下,我将从我发布在http://pastebin.com/uF3nrDuw上的安装程序脚本中提取其中的一些行。

你可以试试:

GrantGenericRead -dsTrustee [adsi]"cn=Agroup,ou=AnOU,dc=dompn,dc=domp0" -dsResources [adsi]"ou=theUnixOU,ou=AnOtherOU,dc=dompn,dc=domp0"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM