Skip to content

Commit

Permalink
Merge pull request #15 from santisq/13/truncate-warning
Browse files Browse the repository at this point in the history
Looks good, thank you @PoshAJ !
  • Loading branch information
santisq authored Sep 7, 2024
2 parents 8cf28c3 + 9883809 commit 2f01962
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 92 deletions.
72 changes: 47 additions & 25 deletions docs/en-US/Get-ADTreeGroupMember.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
external help file: PSADTree.dll-Help.xml
Module Name: PSADTree
online version:
Expand All @@ -20,6 +20,7 @@ Get-ADTreeGroupMember
[-Group]
[-Identity] <String>
[-Server <String>]
[-Credential <PSCredential>]
[-Depth <Int32>]
[-ShowAll]
[-Exclude <String[]>]
Expand All @@ -33,6 +34,7 @@ Get-ADTreeGroupMember
[-Group]
[-Identity] <String>
[-Server <String>]
[-Credential <PSCredential>]
[-Recursive]
[-ShowAll]
[-Exclude <String[]>]
Expand Down Expand Up @@ -99,10 +101,28 @@ The `-ShowAll` switch indicates that the cmdlet should display the hierarchy of
## PARAMETERS

### -Credential

Specifies a user account that has permission to perform this action. The default is the current user.

Type a user name, such as **User01** or **Domain01\User01**, or enter a **PSCredential** object generated by the `Get-Credential` cmdlet. If you type a user name, you're prompted to enter the password.

```yaml
Type: PSCredential
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Depth
Determines the number of nested groups and their members included in the recursion.
By default, only 3 levels of recursion are included.
By default, only 3 levels of recursion are included. `Get-ADTreeGroupMember` emits a warning if the levels exceed this number.

```yaml
Type: Int32
Expand All @@ -116,6 +136,29 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Exclude

Specifies an array of one or more string patterns to be matched as the cmdlet enumerates child principals.
Any matching principal is excluded from the output.
Wildcard characters are accepted.

> [!NOTE]
>
> - Patterns are tested against the principal's `.SamAccountName` property.
> - When the matched principal is of type `group`, all child principals are also excluded from the output.

```yaml
Type: String[]
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True
```

### -Group

The `-Group` switch indicates that the cmdlet should display nested group members only. Essentially, a built-in filter where [`ObjectClass`](https://learn.microsoft.com/en-us/windows/win32/adschema/a-objectclass) is `group`.
Expand Down Expand Up @@ -222,29 +265,6 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Exclude

Specifies an array of one or more string patterns to be matched as the cmdlet enumerates child principals.
Any matching principal is excluded from the output.
Wildcard characters are accepted.

> [!NOTE]
>
> - Patterns are tested against the principal's `.SamAccountName` property.
> - When the matched principal is of type `group`, all child principals are also excluded from the output.

```yaml
Type: String[]
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True
```

### CommonParameters

This cmdlet supports the common parameters. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
Expand All @@ -266,3 +286,5 @@ You can pipe strings containing an identity to this cmdlet. [__`ADGroup`__](http
## NOTES

`treegroupmember` is the alias for this cmdlet.

## RELATED LINKS
70 changes: 46 additions & 24 deletions docs/en-US/Get-ADTreePrincipalGroupMembership.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
external help file: PSADTree.dll-Help.xml
Module Name: PSADTree
online version:
Expand All @@ -19,6 +19,7 @@ schema: 2.0.0
Get-ADTreePrincipalGroupMembership
[-Identity] <String>
[-Server <String>]
[-Credential <PSCredential>]
[-Depth <Int32>]
[-ShowAll]
[-Exclude <String[]>]
Expand All @@ -31,6 +32,7 @@ Get-ADTreePrincipalGroupMembership
Get-ADTreePrincipalGroupMembership
[-Identity] <String>
[-Server <String>]
[-Credential <PSCredential>]
[-Recursive]
[-ShowAll]
[-Exclude <String[]>]
Expand Down Expand Up @@ -95,10 +97,28 @@ The `-ShowAll` switch indicates that the cmdlet should display the hierarchy of
## PARAMETERS

### -Credential

Specifies a user account that has permission to perform this action. The default is the current user.

Type a user name, such as **User01** or **Domain01\User01**, or enter a **PSCredential** object generated by the `Get-Credential` cmdlet. If you type a user name, you're prompted to enter the password.

```yaml
Type: PSCredential
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Depth
Determines the number of nested group memberships included in the recursion.
By default, only 3 levels of recursion are included.
By default, only 3 levels of recursion are included. `Get-ADTreePrincipalGroupMembership` emits a warning if the levels exceed this number.

```yaml
Type: Int32
Expand All @@ -112,6 +132,28 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Exclude

Specifies an array of one or more string patterns to be matched as the cmdlet enumerates child principals.
Any matching principal is excluded from the output.
Wildcard characters are accepted.

> [!NOTE]
>
> Patterns are tested against the principal's `.SamAccountName` property.

```yaml
Type: String[]
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True
```

### -Identity

Specifies an Active Directory principal by providing one of the following property values:
Expand Down Expand Up @@ -202,28 +244,6 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Exclude

Specifies an array of one or more string patterns to be matched as the cmdlet enumerates child principals.
Any matching principal is excluded from the output.
Wildcard characters are accepted.

> [!NOTE]
>
> Patterns are tested against the principal's `.SamAccountName` property.

```yaml
Type: String[]
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True
```

### CommonParameters

This cmdlet supports the common parameters. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
Expand All @@ -245,3 +265,5 @@ You can pipe strings containing an identity to this cmdlet. [`ADObject`](https:/
## NOTES

`treeprincipalmembership` is the alias for this cmdlet.

## RELATED LINKS
35 changes: 18 additions & 17 deletions src/PSADTree/Commands/GetADTreeGroupMemberCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,35 @@ protected override void ProcessRecord()
{
Dbg.Assert(Identity is not null);
Dbg.Assert(_context is not null);
_truncatedOutput = false;

try
{
using GroupPrincipal? group = GroupPrincipal.FindByIdentity(_context, Identity);
if (group is null)
{
WriteError(ErrorHelper.IdentityNotFound(Identity));
WriteError(Exceptions.IdentityNotFound(Identity));
return;
}

WriteObject(
sendToPipeline: Traverse(
groupPrincipal: group,
source: group.DistinguishedName),
enumerateCollection: true);
TreeObjectBase[] result = Traverse(
groupPrincipal: group,
source: group.DistinguishedName);

DisplayWarningIfTruncatedOutput();
WriteObject(sendToPipeline: result, enumerateCollection: true);
}
catch (Exception e) when (e is PipelineStoppedException or FlowControlException)
catch (Exception _) when (_ is PipelineStoppedException or FlowControlException)
{
throw;
}
catch (MultipleMatchesException e)
catch (MultipleMatchesException exception)
{
WriteError(e.AmbiguousIdentity(Identity));
WriteError(exception.AmbiguousIdentity(Identity));
}
catch (Exception e)
catch (Exception exception)
{
WriteError(e.Unspecified(Identity));
WriteError(exception.Unspecified(Identity));
}
}

Expand Down Expand Up @@ -105,13 +107,13 @@ private TreeObjectBase[] Traverse(
_index.TryAddPrincipals();
current?.Dispose();
}
catch (Exception e) when (e is PipelineStoppedException or FlowControlException)
catch (Exception _) when (_ is PipelineStoppedException or FlowControlException)
{
throw;
}
catch (Exception e)
catch (Exception exception)
{
WriteError(e.EnumerationFailure(current));
WriteError(exception.EnumerationFailure(current));
}
}

Expand Down Expand Up @@ -183,7 +185,7 @@ private TreeObjectBase ProcessPrincipal(

TreeObjectBase AddTreeObject(TreeObjectBase obj)
{
if (Recursive.IsPresent || depth <= Depth)
if (depth <= Depth)
{
_index.AddPrincipal(obj);
}
Expand Down Expand Up @@ -211,7 +213,6 @@ TreeObjectBase HandleGroup(

private void EnumerateMembers(TreeGroup parent, int depth)
{
bool shouldProcess = Recursive.IsPresent || depth <= Depth;
foreach (TreeObjectBase member in parent.Childs)
{
if (member is TreeGroup treeGroup)
Expand All @@ -220,7 +221,7 @@ private void EnumerateMembers(TreeGroup parent, int depth)
continue;
}

if (shouldProcess)
if (depth <= Depth)
{
_index.Add(member.Clone(parent, depth));
}
Expand Down
Loading

0 comments on commit 2f01962

Please sign in to comment.