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