• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 839
  • Last Modified:

Powershell Recursive File/Folder Scan

Hi,

I've found this script but i've been trying to get it to sort files by creationdate/time but i can't get it to go through sub folders can anyone spot the issue

Param([string]$path, [string]$filter, [switch]$help)

Function Sort-Files ([string]$path,[string]$filter)
{
 Get-ChildItem -Path $path -Filter $filter | 
 Sort-Object -Property CreationTime
} #end Sort-Files

Function Get-HelpText
{
 $helpText = @"
DESCRIPTION:
  Sorts files by creation date. Accepts parameter for path and file type.
EXAMPLE:
  SortFilesInFolderByCreationDate.ps1 -path c:\fso -filter "*.txt"
  SortFilesInFolderByCreationDate.ps1 -p c:\fso -f *.txt
  SortFilesInFolderByCreationDate.ps1 c:\fso *.txt
"@
 $helpText
} #end Get-HelpText
# *** Entry point to Script ***

if($help) { Get-HelpText ; exit }
Sort-Files -path $path -filter $filter | 
Format-Table -property name, creationtime -AutoSize

Open in new window

0
Alex Young
Asked:
Alex Young
  • 2
2 Solutions
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Instead of :
Get-ChildItem -Path $path -Filter $filter

User:
Get-ChildItem -Path $path -Filter $filter  -recurse
0
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
If you dont want to include the folder names in the result list, use:

Get-ChildItem -Path $path -Filter $filter -recurse -file
0
 
Alex YoungAuthor Commented:
Thank You
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now