Syntax:
Get-ChildItemPlus [-Path] <string> [-Level] <integer> [-Type] <string>
Example 1:
Get-ChildItemPlus c:\temp 2 Folder
This command retrieves all of the folders in the c:\temp path till second level.
Example 2:
Get-ChildItemPlus c:\temp 3 Files
This command retrieves all of the files in the c:\temp path till third level.
Parameters:
- Path
Specifies a path to location
- Level
Specifies a depth to search - e.g. c:\windows\system32 is level 2
- Type
The type of object that Get-ChildItem returns: File, Folder, Both
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
Function Get-ChildItemPlus { Param ([Parameter(Mandatory = $true, ValueFromPipeline = $false, Position = 0)] [string]$Path = ".", [Parameter(Mandatory = $true, ValueFromPipeline = $false, Position = 1)] [int]$Level = 99, [Parameter(Mandatory = $true, ValueFromPipeline = $false, Position = 2)] [string]$Type = "") switch ($Type) { "Folder" {$Data = Get-ChildItem -Path "$Path" -Recurse | Where-Object {$_.psIsContainer -eq $True}} "File" {$Data = Get-ChildItem -Path "$Path" -Recurse | Where-Object {! $_.psIsContainer}} default {$Data = Get-ChildItem -Path "$Path" -Recurse} } if ($Data -eq $Null) {Break} $Level++ $Output = @() foreach ($Item in $Data) { $Folder = $Item.FullName.ToString() if ($Folder.Split("\").Count -le "$Level") { $Output += "$Folder" } } return $Output } |