Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:49:55+00:00 2026-06-13T12:49:55+00:00

Whats the powershell command for finding files in a folder that do not meet

  • 0

Whats the powershell command for finding files in a folder that do not meet a criteria of date range for the Get-Childitem filter of LastWriteTime.

So, check to see if a directory has files that DO NOT contain any files that have LastWriteTime between 01/10/2012 (1st Oct) to 25/10/2012 (25th Oct).

I want to display the folders that DO NOT have any files that are in that range…that way I know they are old and the whole directory can be deleted.

example of this is:

Folder1 – some files written within October – ignore this whole folder and do not display these in the results

Folder2 – NO file has LastWriteTime written in the month of October and so this folder and files should be displayed.

I know this can be done with Get-ChildItem and I am stuck on the bit below..

Get-ChildItem E:\LogArchive -Recurse | Where-Object{$_.LastWriteTime.......?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:49:56+00:00Added an answer on June 13, 2026 at 12:49 pm

    Simple solution off top of the head is this:

    Where-Object{ $_.LastWriteTime -lt $startDate -or $_.LastWriteTime -gt $endDate }
    

    where $startDate is 01/10/2012 (1st Oct) and $endDate is 25/10/2012 (25th Oct).

    Problem with this approach is that it does not account for time factor in the [datetime]. So in your example, if you have 25-Oct-2012 as an upper bound, it will return files created at 25-Oct-2012 9:00, which you may not want.

    Below code calculates [datetime]‘s with time part truncated, based on the input [datetime], and builds the month-to-date date range of ($dayStart, $dayEnd):

    $entry_date = "20-Oct-2012 9:00" #to feed current date, use this: Get-Date
    $dayEnd = Get-Date $entry_date -Minute 0 -Hour 0 -Second -0;
    $dayStart = Get-Date $endDate -Day 1;
    $dayStart, $dayEnd
    

    For this sample code, here is the output:

    Monday, October 01, 2012 12:00:00 AM 
    Saturday, October 20, 2012 12:00:00 AM
    

    Notice this approach is flexible, because you can set $entry_date to either Date or String, and it may or may not have time part – it will work in all those cases. You can then have this code in Where-Object:

    Where-Object{ $_.LastWriteTime -lt $dayStart -or $_.LastWriteTime -ge $dayEnd.AddDays(1) }
    

    Notice how -ge $dayEnd.AddDays(1) fixes the issue when comparing 25-Oct-2012 to 25-Oct-2012 9:00.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my PowerShell script I'm calling some command line tools (not cmdlets) that may
I have the following powershell command that recursively loops through all .sql files in
If I try to run a Powershell Command through c# I get the following
It's easy to copy multiple files to a folder that doesn't exists and let
Many applications have associated help that you invoke by pressing F1. What PowerShell command
How I can write a function or alias a command in PowerShell so that
I am running this Powershell command: Get-counter -Counter \Processor(_Total)\% Processor Time –Continuous Which I
If I issue following command in PowerShell, I get a lot of rows back.
I want to find out what application associates with a port. But Get-Process(Powershell) command
Whats the best/easiest way to test for administrative rights in a PowerShell script? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.