Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net Active Directory中的Powershell访问列表_.net_Windows_Powershell_Active Directory - Fatal编程技术网

.net Active Directory中的Powershell访问列表

.net Active Directory中的Powershell访问列表,.net,windows,powershell,active-directory,.net,Windows,Powershell,Active Directory,我有一个函数GrantGenericRead,当我在同一次运行中创建一个对象$ouUnixGroups时,该函数会起作用。我试图找出如何从AD中获取一个可以运行GrantGenericRead的对象,但似乎当我以我所知道的方式(adsi,lookup using.Path)尝试这个方法时,我无法访问对象的某些属性来设置它。我希望有人告诉我我做错了什么 当所有代码同时运行时,此代码有效: function CreateADGroup([string] $server, [string] $name

我有一个函数
GrantGenericRead
,当我在同一次运行中创建一个对象
$ouUnixGroups
时,该函数会起作用。我试图找出如何从AD中获取一个可以运行
GrantGenericRead
的对象,但似乎当我以我所知道的方式(adsi,lookup using.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
如果有人想看一下的话,我正在从我发布的安装程序脚本中提取其中的一些行。u

您可以试试:

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无法索引到空数组中。在第4行char:40+$binary=$dsObj.psbase.Properties[首先要确保理解,您在此处提供的代码可用于创建组和OU,您只想使用GrantGenericRead aginst现有对象吗?您是否尝试过先对现有对象的DN字符串进行硬编码?如果我在内存中有对象,它会起作用,就像我在此运行期间创建组和OU一样。如果我尝试,请说,从他稍后使用命令行。它不起作用。我尝试过对DN字符串进行硬编码,并使用adsi查找它们然后存储它们,但仍然没有成功。当我从AD调用对象与创建对象时,我没有得到任何损失。[Void]$dsResources.psbase.ObjectSecurity.AddAccessRule($ace),这是它从grantGenericRead方法中保留的行。