Searching files in PowerShell is quite flexible in some
ways.
Why it's flexible? It provides a lot of option that you can
type on cmdlet parameters.
This code below will search for ".doc" and
".docx" files recursively in a given path.
Get-ChildItem -Path "D:\My Docs Folder" -Filter
*.doc* -Recurse
If you have standard file naming convention, or you save
files in a way that you could easily remember then PowerShell can also do it
for you.
Code below will search for any documents that its file name
starts with Feb or feb.
Get-ChildItem -Path "D:\My Docs Folder" -Filter
Feb*.doc* -Recurse
It's just document, the file name extension can be replace with *.xls*
to search for excel worksheets or any file name extension such as ".png" or ".jpeg" or other video files or any type of file.
Or if you searching for saved outlook messages, use *.msg to
search for saved outlook emails.
If you want to search by file size, PowerShell can also do
the task.
Example below will search for any PDF files which size is
greater than 3 megabytes or 3MB.
Get-ChildItem -Path "D:\My PDF Files" -Filter
*.pdf -Recurse |
Where-Object {$_.Length -gt 3MB}
If need to search by file creation date, see example below:
Get-ChildItem -Path "D:\My Documents" -Filter
*.doc* -Recurse |
Where-Object {$_.CreationTime.Date -match "2013"}
Example above will search for files created on year 2013.
Example below will search for text files modified on the
current date.
$xtoday = (get-date).Date
Get-ChildItem -Path "D:\My Documents" -Filter
*.txt -Recurse |
Where-Object {$_.LastWriteTime.Date -match $xtoday }
That is just few examples on how PowerShell can do to search
for files, the rest will depends on what creativity can brings.
To check for files or folder modified on last X minutes check out link below:
http://quickbytesstuff.blogspot.sg/2014/04/powershell-check-folder-for-modified.html
http://quickbytesstuff.blogspot.sg/2014/04/powershell-check-folder-for-modified.html
Cheers!! Hope it helps...
Comments
Post a Comment