Script to get folder hierichy, file count and required days files in the windows server

sns 9,236 Reputation points
2023-08-28T17:22:32.8633333+00:00

I am looking for folder structure , file count , size , date created and date modified.

file majorily i am looking for a. file less than 30 days b. files less than 1 day c. File greater than 30 days

and finally exporting in to excel.

If there is any script, Please share it, thank you.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,521 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 33,481 Reputation points
    2023-08-28T22:58:53.6966667+00:00

    There are plenty of examples out on the internet. You will learn a lot more if you do a little searching and try to write it yourself. Then ask a question about what you can't figure out.

    https://www.bing.com/search?q=powershell+examples+folder+list

    Use this as a reference.

    https://www.sapien.com/books_training/Windows-PowerShell-4

    0 comments No comments

  2. Ian Xue 36,751 Reputation points Microsoft Vendor
    2023-08-29T05:10:35.34+00:00

    Hi,

    You can get files using the Get-ChildItem cmdlet and filter with a specific file property by Where-Object

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-7.3

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/where-object?view=powershell-7.3

    For example, to list the files less than 30 days, you can filter with the LastWriteTime property.

    $date=(Get-Date).AddDays(-30)
    Get-ChildItem -Path C:\Folder | Where-Object {$_.LastWriteTime -gt $date}
    

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.