Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@

</div>

PSADTree is a PowerShell module that brings `tree`-like visualization to Active Directory group structures — perfect for spotting nested membership and circular references at a glance.
PSADTree is a PowerShell module that brings intuitive `tree`-like visualization to Active Directory group structures. It helps administrators and security professionals quickly understand nested group memberships, identify effective permissions, and spot potential circular references at a glance.

This Module currently includes two cmdlets:
## Cmdlets

- [Get-ADTreeGroupMember](docs/en-US/Get-ADTreeGroupMember.md) for AD Group Members.
- [Get-ADTreePrincipalGroupMembership](docs/en-US/Get-ADTreePrincipalGroupMembership.md) for AD Principal Group Membership.
- **`Get-ADTreeGroupMember`**
Displays the members of an Active Directory group in a clear hierarchical tree view. It recursively shows nested groups, users, computers, and other principals, making it easy to visualize complex group nesting.

__Both cmdlets help with discovery of Circular Nested Groups.__
- **`Get-ADTreePrincipalGroupMembership`**
Shows all groups that a given Active Directory principal (user, computer, group, etc.) belongs to, presented in a tree structure. This reverse view is especially useful for understanding effective membership and troubleshooting access issues.

- **`Get-ADTreeStyle`**
Retrieves the singleton `TreeStyle` instance used to customize the colored, hierarchical output of `Get-ADTreeGroupMember` and `Get-ADTreePrincipalGroupMembership`.
Allows you to change colors for groups, users, computers, other principals, and apply accents. You can also control ANSI output rendering.

## Documentation

Check out [__the docs__](./docs/en-US/PSADTree.md) for information about how to use this Module.
- Learn how to use the cmdlets in the [official documentation](./docs/en-US/).

- To Customize output rendering, see [about_TreeStyle](./docs/en-US/about_TreeStyle.md).

## Installation

Expand Down Expand Up @@ -170,7 +177,7 @@ mail john.doe@mylab.com

>[!TIP]
>
> - `-Properties *` retrieves __all__ available attributes from each object.
> - `-Properties *` retrieves **all** available attributes from each object.
> - Use friendly names (e.g. `Country` → `c`, `City` → `l`, `PasswordLastSet` → `pwdLastSet`) or raw LDAP names — the key in `.AdditionalProperties` matches what you requested.
> - See the full list of supported friendly names in the [source code `LdapMap.cs`](https://github.com/santisq/PSADTree/tree/main/src/PSADTree/LdapMap.cs)

Expand Down Expand Up @@ -274,4 +281,4 @@ ChildDomain group └── Users

## Contributing

Contributions are more than welcome, if you wish to contribute, fork this repository and submit a pull request with the changes.
Contributions are welcome, if you wish to contribute, fork this repository and submit a pull request with the changes.
Binary file added assets/EscapeSequence.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Get-ADTreeGroupMember.After.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Get-ADTreeGroupMember.Before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/TreeStyle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions docs/en-US/Get-ADTreeStyle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
external help file: PSADTree.dll-Help.xml
Module Name: PSADTree
online version: https://github.com/santisq/PSADTree/blob/main/docs/en-US/Get-ADTreeStyle.md
schema: 2.0.0
---

# Get-ADTreeStyle

## SYNOPSIS

Retrieves the `TreeStyle` instance used for output rendering.

## SYNTAX

```powershell
Get-ADTreeStyle
[<CommonParameters>]
```

## DESCRIPTION

The `Get-ADTreeStyle` cmdlet provides access to the `TreeStyle` instance that controls the rendering and customization
of output for the `Get-ADTreeGroupMember` and `Get-ADTreePrincipalGroupMembership` cmdlets.

To Customize output rendering, see [about_TreeStyle](about_TreeStyle.md).

## EXAMPLES

### Example 1

```powershell
PS ..\PSADTree> $style = Get-ADTreeStyle
```

Stores the `TreeStyle` instance in the `$style` variable.

## PARAMETERS

### CommonParameters

This cmdlet supports the common parameters. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### None

## OUTPUTS

### TreeStyle

## NOTES

Modifying the properties of this object (such as colors for groups, users, computers, etc.) will immediately affect the
visual output of `Get-ADTreeGroupMember` and `Get-ADTreePrincipalGroupMembership` in the current PowerShell session.

## RELATED LINKS

[__`Get-ADTreeGroupMember`__](Get-ADTreeGroupMember.md)

[__`Get-ADTreePrincipalGroupMembership`__](Get-ADTreePrincipalGroupMembership.md)

[__about_TreeStyle__](about_TreeStyle.md)
102 changes: 102 additions & 0 deletions docs/en-US/about_TreeStyle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# about_TreeStyle

## TOPIC

Customizing PSADTree Output with TreeStyle.

## SHORT DESCRIPTION

The `TreeStyle` class enables customization of the hierarchical output for `Get-ADTreeGroupMember` and `Get-ADTreePrincipalGroupMembership` cmdlets in the PSADTree module.

## LONG DESCRIPTION

PSADTree version 1.3.0 and later introduces support for coloring the hierarchical output of the `Get-ADTreeGroupMember` and `Get-ADTreePrincipalGroupMembership` cmdlets using the `TreeStyle` class. This class provides a subset of features similar to those in PowerShell’s built-in [PSStyle][1].
You can access the singleton instance of `TreeStyle` through either the [Get-ADTreeStyle][2] cmdlet or the `[PSADTree.Style.TreeStyle]::Instance` property:

<div>
&nbsp;&nbsp;&nbsp;
<img src="../../assets/TreeStyle.png" alt="TreeStyle" width="50%" height="50%">
</div>

The `TreeStyle` class offers methods for combining escape sequences and applying text accents, such as bold or italic. See the next section for additional details.

Here are its members:

```powershell
TypeName: PSADTree.Style.TreeStyle

Name MemberType Definition
---- ---------- ----------
CombineSequence Method string CombineSequence(string left, string right)
Equals Method bool Equals(System.Object obj)
EscapeSequence Method string EscapeSequence(string vt)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ResetSettings Method void ResetSettings()
ToBold Method string ToBold(string vt)
ToItalic Method string ToItalic(string vt)
ToString Method string ToString()
OutputRendering Property PSADTree.Style.OutputRendering OutputRendering {get;set;}
Palette Property PSADTree.Style.Palette Palette {get;}
Principal Property PSADTree.Style.PrincipalStyle Principal {get;}
RenderingStyle Property PSADTree.Style.RenderingStyle RenderingStyle {get;set;}
Reset Property string Reset {get;}
```

The `.EscapeSequence()` method reveals the escape sequence applied to generate specific colors or accents. For example:

<div>
&nbsp;&nbsp;&nbsp;
<img src="../../assets/EscapeSequence.png" alt="EscapeSequence" width="50%" height="50%">
</div>

## CUSTOMIZING OUTPUT

You can customize the output by modifying the properties of the `TreeStyle` class, much like you would with PowerShell’s `PSStyle`. This allows you to update colors for computers, groups, and users, as well as the circular and processed tags.

Consider the standard output of `Get-ADTreeGroupMember`:

<div>
&nbsp;&nbsp;&nbsp;
<img src="../../assets/Get-ADTreeGroupMember.Before.png" alt="Get-ADTreeGroupMember.Before" width="60%" height="60%">
</div>

You can adjust the appearance by modifying the `PSADTree.Style.TreeStyle` object. Here’s an example of how to apply customizations:

```powershell
$style = Get-ADTreeStyle
$palette = $style.Palette

# Update users to white text on a red background
$style.Principal.User = $style.CombineSequence($palette.Foreground.White, $palette.Background.Red)

# Change the rendering style to use ASCII
$style.RenderingStyle = 'Classic'
```

> [!TIP]
>
> - PowerShell 6 and later support the `` `e `` escape character for VT sequences. For __Windows PowerShell 5.1__, use `[char] 27` instead. For example, replace ``"`e[45m"`` with `"$([char] 27)[45m"`. See [about_Special_Characters][3] for more details.
> - The `TreeStyle` class provides methods like `.ToItalic()`, `.ToBold()`, and `.CombineSequence()` to apply text accents or combine VT sequences.
> - To reset the `TreeStyle` instance to its default state, use `.ResetSettings()`. If stored in a variable, reassign it afterward, e.g., `$style.ResetSettings()` followed by `$style = Get-ADTreeStyle`.

After applying these changes, re-running the same `Get-ADTreeGroupMember` command will display the updated styles:

<div>
&nbsp;&nbsp;&nbsp;
<img src="../../assets/Get-ADTreeGroupMember.After.png" alt="Get-ADTreeGroupMember.After" width="60%" height="60%">
</div>

## DISABLING ANSI OUTPUT

Just like PowerShell’s `PSStyle`, you can disable ANSI rendering in PSADTree’s output by modifying the `.OutputRendering` property of the `TreeStyle` instance. Simply set it to `'PlainText'` using the following command:

```powershell
(Get-ADTreeStyle).OutputRendering = 'PlainText'
```

This disables all ANSI-based coloring and formatting, resulting in plain text output for commands like `Get-ADTreeGroupMember` and `Get-ADTreePrincipalGroupMembership`. It’s a straightforward way to simplify the display when you don’t need the extra visual styling.

[1]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_ansi_terminals
[2]: ./Get-ADTreeStyle.md
[3]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_special_characters?view=powershell-7.4
46 changes: 0 additions & 46 deletions module/PSADTree.Format.ps1xml

This file was deleted.

Loading