来自不同域的Get-Acl

时间:2016-06-01 13:30:26

标签: powershell

审核员在几个不同的域中询问有关ACL的问题。我已经整理了一个脚本,该脚本返回我的主域(帐户)所需的信息,但似乎无法将其切换到另一个域(Medco)以获取这些组的ACL。如何切换Get-Acl cmdlet以读取其他域中的信息?

Get-Content 'U:\ad\scripts\Scripts - Input\ADGroup Permissions - Medco.txt' | ForEach-Object {
  $OutputG = $_
  $Group = "AD:" + (Get-ADgroup $_ -Server Medco).distinguishedname
  (Get-Acl $Group).access |
    Where-Object {
      $_.ActiveDirectoryRights -like "*write*" -or
      $_.ActiveDirectoryRights -like "*delete*"
    } |
    Sort-Object IdentityReference |
    Select-Object identityreference,
      @{L='Access'; E={$_.ActiveDirectoryRights -join ";"}},
      @{"n"="Group";"e"={"$OutputG"}}
} | Export-csv ".\Scripts - Output\ACL_Medco_$CurrentDate.csv" -NoTypeInformation

该方案是我从.txt文件中读取特定域的组名,然后ForEach-Object传递组名以让distinguishedName在{{Get-Acl中使用它1}}。主域的第一组组正确返回信息(不显示该部分)。我知道这些组存在于下一个域中,但问题是它的Get-Acl引发错误说

Get-Acl : Cannot find path 'AD:CN=Medco Infrastructure & Security,OU=Recipients -
Distribution Lists,OU=Legacy Exchange 5.5,OU=Exchange,DC=medco,DC=com' because it
does not exist.
At line:4 char:4
+   (Get-Acl $Group).access
+    ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-Acl], ItemNotFoundException
    + FullyQualifiedErrorId : GetAcl_PathNotFound_Exception, Microsoft.PowerShell.Commands.GetAclCommand

2 个答案:

答案 0 :(得分:1)

您应该使用New-PSDrive创建新的AD查询提供程序,而不是默认的AD:。然后,您将查询该新驱动器而不是默认驱动器。 例如:

New-PSDrive -Name AD2 -PSProvider ActiveDirectory -Server 'DC.medco.com' -root "//RootDSE/"

$Group = 'AD2:' + (Get-ADgroup $_ -Server Medco).distinguishedname
(Get-Acl $Group).access |
. . . 

如果您想动态分配服务器,可以使用类似

的内容
(Get-ADDomainController -DomainName 'medco.com' -Discover).hostName

如果需要,您可以从现有的尊贵名称

获取域名

如果您有两个以上的域名,那么在设置具有相同名称的新域名之前,您应该使用Remove-PSDrive。最好的方法是每个域对AD组进行分组,以最大限度地减少添加/删除命令。

答案 1 :(得分:0)

这会有所帮助,但一定要包括 -Identity-Server 参数,以确保获得正确的结果。我是为 Get-ADComputer 这样做的,但它也适用于 Get-ADObject:

New-PSDrive -Name AD2 -PSProvider ActiveDirectory -Server 'my.other.subnet.net' -root "//RootDSE/"    
$Group = 'AD:' + (Get-ADComputer -Identity 'FakeComputer-01' -Server 'my.other.subnet.net').distinguishedname    
(Get-Acl $Group).access

有时不包括其他参数仍然会返回错误。