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

powershell script to create a report of all folders-subfolders a files that matches with a specific criteria in Windows 2012

Hi Experts,

My manager asked me to generate a report  of all folders/subfolder and files that matches with a specific criteria, for example all folders/sub-folders, files where the name of file and the body and or subject is "CONTRACT" then export all info ont a CSV file

I actually have a WIndows server 2012 cluster with multiple nodes, and this cluster is the repository of data of all users'network map drive.

I should be able to find any docs based on a specific criteria such as file/folder name, subject and body. From windows explorer and can perform a search for folders/sub-folders and files based on specific criteria, but i would like to be able to perform this from powershell and generate a report that i can send to all managers

Any ideas?
Jerry Seinfield
Jerry Seinfield
1 Solution
Rob StoneCommented:
You can try this:

$Criteria = $null
$Path = $null
$Logpath = $null
$Logfile = $null
$date = $null
$Search = $null

$Criteria = Read-Host "Enter the search string here"
$Path = Read-Host "Enter the Path to run the query against"
$Logpath = "C:\Users\Robsto.ent"
$Logfile = "Report_"$Criteria
$Date = Get-Date -Format yyyyMMdd_

$Search = gci -Path $Path -Filter $Criteria -Recurse |Select-Object Fullname, Name, Extension
$Search |Export-CSV -Path "$Date+$LogFile.csv"

Open in new window

Note, I've put the '-Resurse' switch in which can take ages on a large file structure.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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