Skip to content

Latest commit

 

History

History
290 lines (210 loc) · 7.09 KB

Get-PSTree.md

File metadata and controls

290 lines (210 loc) · 7.09 KB
external help file Module Name online version schema
PSTree.dll-Help.xml
PSTree
2.0.0

Get-PSTree

SYNOPSIS

tree like cmdlet for PowerShell.

SYNTAX

Path (Default)

Get-PSTree
    [[-Path] <String[]>]
    [-Depth <UInt32>]
    [-Recurse]
    [-Force]
    [-Directory]
    [-RecursiveSize]
    [-Exclude <String[]>]
    [-Include <String[]>]
    [<CommonParameters>]

LiteralPath

Get-PSTree
    [-LiteralPath <String[]>]
    [-Depth <UInt32>]
    [-Recurse]
    [-Force]
    [-Directory]
    [-RecursiveSize]
    [-Exclude <String[]>]
    [-Include <String[]>]
    [<CommonParameters>]

DESCRIPTION

Get-PSTree is a PowerShell cmdlet that intends to emulate the tree command with added functionalities to calculate the folders size as well as recursive folders size.

EXAMPLES

Example 1: Get the current directory tree with default parameters values

PS ..\PSTree> Get-PSTree

The default parameter set uses -Depth with a value of 3. No hidden and system files folder are displayed and recursive folder size is not calculated.

Example 2: Get the $HOME tree recursively displaying only folders

PS ..\PSTree> Get-PSTree $HOME -Directory -Recurse

In this example $HOME is bound positionally to the -Path parameter.

Example 3: Get the $HOME tree 2 levels deep displaying hidden files and folders

PS ..\PSTree> Get-PSTree -Depth 2 -Force

The -Force switch is needed to display hidden files and folders. In addition, hidden child items do not add up to the folders size without this switch.

Example 4: Get the C:\ drive tree 2 levels in depth displaying only folders calculating the recursive size

PS ..\PSTree> Get-PSTree C:\ -Depth 2 -RecursiveSize -Directory

Example 5: Get the $HOME tree recursively excluding all .jpg and .png files

PS ..\PSTree> Get-PSTree $HOME -Recurse -Exclude *.jpg, *.png

The -Exclude parameter supports wildcard patterns, exclusion patterns are tested against the items .FullName property. Excluded items do not do not add to the folders size.

Example 6: Get the tree of all folders in a location

PS ..\PSTree> Get-ChildItem -Directory | Get-PSTree

DirectoryInfo and FileInfo instances having the PSPath Property are bound to the -LiteralPath parameter.

Example 7: Get the tree of all folders in a location including only *.ps1 files

PS ..\PSTree> Get-ChildItem -Directory | Get-PSTree -Include *.ps1

Similar to -Exclude, the -Include parameter supports wildcard patterns, however, this parameter works only with Files.

PARAMETERS

-Depth

Determines the number of subdirectory levels that are included in the recursion.

Type: UInt32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: 3
Accept pipeline input: False
Accept wildcard characters: False

-Directory

Use this switch to display Directories only.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Exclude

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

Excluded items do not add to the recursive folders size.

Note

  • Patterns are tested against the object's .FullName property.
  • The -Include and -Exclude parameters can be used together and the inclusions are applied after the exclusions.
Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

-Force

Gets items that otherwise can't be accessed by the user, such as hidden or system files.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Include

Specifies an array of one or more string patterns to be matched as the cmdlet gets child items. Any matching item is included in the output. Wildcard characters are accepted.

Note

  • Patterns are tested against the object's .FullName property.
  • This parameter focuses only on files, the inclusion patterns are only evaluated against FileInfo instances.
  • The -Include and -Exclude parameters can be used together and the inclusions are applied after the exclusions.
Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

-LiteralPath

Absolute or relative folder path. Note that the value is used exactly as it's typed. No characters are interpreted as wildcards.

Type: String[]
Parameter Sets: LiteralPath
Aliases: PSPath

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Path

Specifies a path to one or more locations. Wildcards are accepted. The default location is the current directory (.).

Type: String[]
Parameter Sets: Path
Aliases:

Required: False
Position: 0
Default value: Current directory
Accept pipeline input: True (ByValue)
Accept wildcard characters: True

-Recurse

Gets the items in the specified location and in all child items of the location.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-RecursiveSize

This switch enables the cmdlet to calculate the recursive size of folders in a hierarchy. By default, the cmdlet only displays the size of folders based on the sum of the file's Length in each directory. It's important to note that this is a more expensive operation, in order to calculate the recursive size, all items in the hierarchy needs to be traversed.

By default, the size of hidden and system items is not added to the recursive size, for this you must use the -Force parameter. Excluded items with the -Exclude parameter do not add to the recursive size.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters. For more information, see about_CommonParameters.

INPUTS

String

You can pipe a string that contains a path to this cmdlet. Output from Get-Item and Get-ChildItem can be piped to this cmdlet.

OUTPUTS

PSTreeDirectory

PSTreeFile