[英]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.