【问题标题】:Powershell access lists in Active DirectoryActive Directory 中的 Powershell 访问列表
【发布时间】:2012-04-05 04:10:27
【问题描述】:

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

这段代码在同时运行时有效:

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 上发布的安装程序脚本中提取其中的一些行。你

【问题讨论】:

    标签: .net windows powershell active-directory


    【解决方案1】:

    你可以试试:

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

    【讨论】:

    • 恐怕我试过 PS C:\Windows\system32> GrantGenericRead -dsTrustee [adsi]$joinOps.Path -dsResources [adsi]$ouUnixGroups.Path 无法索引到空数组。在 line:4 char:40 + $binary = $dsObj.psbase.Properties[
    • 首先一定要明白,您在此处提供的代码用于创建组和 OU,您只是想使用 GrantGenericRead 对现有对象?您是否首先尝试对现有对象的 DN 字符串进行硬编码?
    • 如果我在内存中有对象,它就可以工作,就像我在此运行期间创建组和 OU 一样。如果我尝试说,稍后从命令行。它不起作用。我已经尝试对 DN 字符串进行硬编码,并使用 adsi 查找它们然后存储它们,仍然没有骰子。当我从 AD 调用对象而不是创建它时,我没有得到我丢失的东西。
    猜你喜欢
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    相关资源
    最近更新 更多