Cmdlet that intends to emulate the tree
command and also calculate the folder's total size.
-
06/19/2022
- Added format view for the Module -
PSTree.Format.ps1xml
. - The module now uses
EnumerateFiles()
andEnumerateDirectories()
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
andPSTreeFile
instances now only include 2 visible properties,Hierarchy
andLength
, the rest is done with format view.
- Added format view for the Module -
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
-
05/24/2022
- Lots of code improvements have been done to the Module and improved error handling. Now uses the
GetDirectories()
andGetFiles()
methods fromSystem.IO.DirectoryInfo
. EachPSTreeDirectory
instance now holds an instance ofDirectoryInfo
.System.Collections.Stack
has been changed forSystem.Collections.Generic.Stack<T>
.
- Lots of code improvements have been done to the Module and improved error handling. Now uses the
-
04/21/2022
- PSTree Module now uses
System.Collections.Stack
instead of recursion, perfomance should be much better now and functionality remains the same. Special thanks to IISResetMe.
- PSTree Module now uses
-
01/02/2022
- PSTree Module now has it's own classes, functionality remains the same however a lot has been improved.
- Recursion is now done using the static methods
[System.IO.Directory]::GetDirectories()
and[System.IO.Directory]::GetFiles()
instead ofGet-ChildItem
.
-
12/25/2021
-Files
switch has been added to the Module, now you can display files in the hierarchy tree if desired.Type
property has been added to the output object and is now part of the Default MemberSet.
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 |
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;}
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;}
- Tested and compatible with PowerShell v5.1 and PowerShell Core.
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 thePSTree
folder to your$env:PSModulePath
.
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 theuser
directory with a maximum of 10 levels of recursion.Get-PSTree /home/user -Recurse
Gets the hierarchy and folder size of theuser
directory and all folders below.
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