查询AD需要嵌套组信息

时间:2017-04-30 16:40:30

标签: powershell active-directory nested

我有以下脚本,我还需要查询以获取嵌套组(如果存在),如果有,嵌套groupid和嵌套组名称包含在下面的导出中,如果嵌套组不存在,我需要它们用空的GUID填充它。

这就是我在下面的内容。

$OU |
  ForEach {
    $countUser = (Get-ADGroupMember $group.DistinguishedName).Count
    Get-ADGroup -Filter * -Properties ManagedBy, DistinguishedName, objectGUID -SearchBase $_ 
  } | ForEach-Object {
    $managedBy = $_.managedBy;
    $DistinguishedName = $_.DistinguishedName;
    $GroupID = $_.objectGUID;

    if ($managedBy -ne $null) {
      $manager = (Get-ADUser -Identity $managedBy -Properties emailAddress, sn, displayName);
      $managerName = $manager.Name;
      $displayName = $manager.displayName
      $managerEmail = $manager.emailAddress;
      $managerID = $manager.objectGUID;
      $managerFName = $manager.givenName;
      $managerLName = $manager.sn;
      $managerDesc = $manager.description;
      $managertype = $manager.employeeType;
      $managerDistinguishedName = $manager.DistinguishedName;
    } else {
      $managerName = '';
      $managerEmail = '';
      $managerID = '00000000-0000-0000-0000-000000000000';
      $managerFName = '';
      $managerLName = '';
      $managerDesc = '';
      $managertype = '';
    }
    Write-Output $_;
  } |
  Select-Object @{n='TASKIDID';e={$TaskID}}, @{n='GroupID';e={$GroupID}},
    @{n='Group Name';e={$_.Name}}, @{n='ManagerID';e={$managerID}},
    @{n='displayName';e={$displayName}},
    @{n='Managed By Email';e={$managerEmail}}, 
    @{n='Description';e={$managerDesc}},
    @{n='GroupDistinguishingName';e={$DistinguishedName}},
    @{n='managerDistinguishedName';e={managerDistinguishedName}} |
  Export-Csv c:\aatest\_GetGroupOwners.csv -NoTypeInformation

1 个答案:

答案 0 :(得分:1)

如果你只需要一个级别,你可以从循环所在的当前对象获得所需的所有信息。

    find \! -name "output.txt" -printf '%P\n' > output.txt