eizedev / PSTree

tree like command for PowerShell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PSTree

DESCRIPTION

Cmdlet that intends to emulate the tree command and also calculate the folder's total size.


CHANGELOG

  • 06/19/2022

    • Added format view for the Module - PSTree.Format.ps1xml.
    • The module now uses EnumerateFiles() and EnumerateDirectories() instance methods.
    • Improved error handling (a lot).
    • -Files parameter has been replaced with -Directory parameter, now the module displays files by default.
    • -Deep parameter has been replaced with -Recurse parameter, same functionality.
    • PSTreeDirectory and PSTreeFile instances now only include 2 visible properties, Hierarchy and Length, the rest is done with format view.
PS /home/user/.local/share/powershell/Modules> gpstree . -Recurse

Mode     Hierarchy                                                          Size
----     ---------                                                          ----
d----    PSTree                                                             11.5 KB
-a---    ├── install.ps1                                                    1.82 KB
-a---    ├── LICENSE                                                        1.07 KB
-a---    ├── README.md                                                      8.61 KB
d----    └── PSTree                                                         4.52 KB
-a---        ├── PSTree.psd1                                                4.16 KB
-a---        ├── PSTree.psm1                                                372 B
d----        ├── public                                                     3.74 KB
-a---        │   └── Get-PSTree.ps1                                         3.74 KB
d----        ├── private                                                    0 B
d----        │   └── classes                                                3.01 KB
-a---        │       └── PSTree Classes.ps1                                 3.01 KB
d----        └── Format                                                     1.81 KB
-a---            └── PSTree.Format.ps1xml                                   1.81 KB

PARAMETER

Parameter Name Description
-Path <string> Absolute or relative folder path. Alias: FullName
[-Depth <int>] Specifies the maximum level of recursion
[-Recurse <switch>] Recursion until maximum level is reached
[-Force <switch>] Display hidden and system files and folders
[-Directory <switch>] Display only Directories in the Hierarchy tree
[<CommonParameters>] See about_CommonParameters

OUTPUTS Object[]

PSTreeDirectory Class

   TypeName: PSTreeDirectory

Name                     MemberType Definition
----                     ---------- ----------
EnumerateDirectories     Method     System.Collections.Generic.IEnumerable[System.IO.DirectoryInfo] EnumerateDirectories()
EnumerateFiles           Method     System.Collections.Generic.IEnumerable[System.IO.FileInfo] EnumerateFiles()
EnumerateFileSystemInfos Method     System.Collections.Generic.IEnumerable[System.IO.FileSystemInfo] EnumerateFileSystemInfos()
Equals                   Method     bool Equals(System.Object obj)
GetHashCode              Method     int GetHashCode()
GetType                  Method     type GetType()
ToString                 Method     string ToString()
Hierarchy                Property   string Hierarchy {get;set;}
Length                   Property   long Length {get;set;}

PSTreeFile Class

Properties

   TypeName: PSTreeFile

Name        MemberType Definition
----        ---------- ----------
Equals      Method     bool Equals(System.Object obj)
GetHashCode Method     int GetHashCode()
GetType     Method     type GetType()
ToString    Method     string ToString()
Hierarchy   Property   string Hierarchy {get;set;}
Length      Property   long Length {get;set;}

COMPATIBILITY

  • Tested and compatible with PowerShell v5.1 and PowerShell Core.

How to install?

  • install.ps1 can be used to download and install the Module automatically:
Invoke-RestMethod https://raw.githubusercontent.com/santysq/PSTree/main/install.ps1 | Invoke-Expression
  • Alternatively, you can git clone or download the .zip and extract the PSTree folder to your $env:PSModulePath.

How to use?

  • Get-PSTree . Gets the hierarchy and folder size of the current directory using default Depth (3).
  • Get-PSTree C:\users\user -Depth 10 -Force Gets the hierarchy and folder size, including hidden ones, of the user directory with a maximum of 10 levels of recursion.
  • Get-PSTree /home/user -Recurse Gets the hierarchy and folder size of the user directory and all folders below.

Example

PS D:\> $tree = gpstree C:\Windows\System32\ -Directory -Depth 2 -EA 0
PS D:\> $tree | Select-Object -First 20

Mode     Hierarchy                                                          Size
----     ---------                                                          ----
d----    System32                                                           2.1 GB
d----    ├── zh-TW                                                          204.5 KB
d----    ├── zh-CN                                                          234.49 KB
d----    ├── winrm                                                          0 B
d----    │   └── 0409                                                       100.12 KB
d----    ├── WinMetadata                                                    6.13 MB
d----    ├── winevt                                                         0 B
d----    │   ├── TraceFormat                                                0 B
d----    │   └── Logs                                                       261.52 MB
d----    ├── WindowsPowerShell                                              0 B
d----    │   └── v1.0                                                       1.73 MB
d----    ├── WinBioPlugIns                                                  1.86 MB
d----    │   ├── FaceDriver                                                 680.34 KB
d----    │   └── en-US                                                      0 B
d----    ├── WinBioDatabase                                                 1.12 KB
d----    ├── WCN                                                            0 B
d----    │   └── en-US                                                      0 B
d----    ├── wbem                                                           66.35 MB
d----    │   ├── xml                                                        99.87 KB
d----    │   ├── tmf                                                        0 B

About

tree like command for PowerShell

License:MIT License


Languages

Language:PowerShell 100.0%