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

  • Home
  • SEARCH
  • 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 8732359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:25:33+00:00 2026-06-13T09:25:33+00:00

Something wrong with my IF-ELSE statement and my dumb brain cannot figure out what

  • 0

Something wrong with my IF-ELSE statement and my dumb brain cannot figure out what the heck it is!

If I run the below code on its own it shows each directory and files in there in the below format:

get-childitem E:\LogArchive -recurse | where-object {$_.lastwritetime -gt 60}

Format of output:

    Directory: E:\LogArchive\W3SVC100


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-----        29/03/2007     15:03        663 ex070329.log.gz
-----        30/03/2007     15:44        860 ex070330.log.gz
-----        03/04/2007     13:41        354 ex070403.log.gz
-----        05/04/2007     14:00        704 ex070405.log.gz
-----        10/04/2007     17:56        921 ex070410.log.gz
-----        11/04/2007     14:55        987 ex070411.log.gz
-----        12/04/2007     15:12        539 ex070412.log.gz

However, when this is run in a code it shows as the below, WITHOUT all the folder structure and dates etc:

W3SVC100
W3SVC102
W3SVC105
W3SVC106
W3SVC1108492480
W3SVC112
W3SVC116
W3SVC118
W3SVC1209046175
W3SVC123110214
W3SVC1262336480
W3SVC127
W3SVC134
W3SVC134239081
W3SVC137
W3SVC139
W3SVC145
W3SVC147
W3SVC1499983181
W3SVC15

How do I get the first results when the below script is run – so show all the modified date, last write time etc . I am currently inputting a message to the user if no files are found in the date range then a message is displayed – however, if it did find anyfiles then display them as listed in the first output type…….

I actually think the fault is on this line but cannot figure out how to amend this:

if ( $runchilditem.lastwritetime -gt DateToCompare) 

……In fact – I want to put the output to CSV – any ideas how I can do this?

CODE:

$path = Read-Host "Please enter the path of the folder yu wish to check - this will check sub-folders as well"
Write-Host "`n"
$days = Read-Host "Please enter in number of DAYS you wish to go back"

$DateToCompare = (Get-Date).AddDays(-$days)

$runningtrue = Get-ChildItem $path -Recurse | where-object {$_.lastwritetime -gt $DateToCompare}

Write-Host "`n"
$runchilditem = @(Get-ChildItem $path -Recurse)
    if ( $runchilditem.lastwritetime -gt DateToCompare) 
        {
            Write-Host "No Files Matching Date Criteria Found"
        }
    else
        {
            $runningtrue
        }
  • 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-13T09:25:34+00:00Added an answer on June 13, 2026 at 9:25 am

    If I understand your need, here is how I would do it:

    $path = Read-Host 'Path'
    [int]$dayDiff = Read-Host 'Number of days to go back'
    $offset = $dayDiff * -1
    $files = Get-ChildItem $path -Recurse | Where-Object{$_.LastWriteTime -gt (Get-Date).AddDays($offset)}
    if(($files.Count -eq 0) -OR ($files -eq $null)){
        'There are no files after {0} in {1}' -f (Get-Date).AddDays($offset), $path
    }else{
        $files
        $files | Export-CSV C:\PATH\TO\FILE.csv -NoTypeInfo
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Else statement not working properly in foreach loop? Here's my code. If something's wrong
I know I'm doing something wrong, but I can't figure out what I'm doing
There is something wrong with my code. I am teaching myself c# and one
I have a fairly simple if else statement in C# that looks something like
Problem Statement:- In my below code, I am getting list of User's which I
Problem part of the code: while counter < length: if something: else: for key,value
I am getting Syntax Error on the else statement in the following code :
I must be doing something wrong here. I'm trying to use Google Analytics to
(Maybe I am doing something wrong but) I am getting awful read performance from
Perhaps I am doing something wrong while z-normalizing my array. Can someone take a

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.