Finding date and size of a file written to a specific directlory

Hi, all -

My challenge:
I have a set of batch scripts that are archiving(by way of WinRAR) and then copying(by way of RoboCopy) an archive of file backups from hundreds of on-prem servers. The scripts are running fine(best I can tell) but I need some reporting of success/failure of the scripts.

My initial approach:
My thought is to write a PS script that will traverse the locations of the backups(each is stored in a separate folder based on the region of the country the server is in) and then create a log that contains information on backups that 1) didn’t create and pull an archive at all, 2) didn’t create and pull and archive for the current day, 3) pulled an archive that is under a certain size

So far this is my script - Get-ChildItem -Path f:\ -Include *.rar -File -Recurse -ErrorAction SilentlyContinue | Out-File -FilePath f:@scripts_logs\results.txt

but I’m struggling to figure out what I need to add to it the logic mentioned above(i.e. date of the file creation, file doesn’t exist at all, size is smaller than it should be).

Ideally, I then would like to have this log sent to me via email on a daily basis after all the backups should have completed.

Welcome to the forum. :wave:t4:

Before we proceed …
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

That sound like you’re using a tinkered solution where it may be more professional to use a professional solution - inluding logging and error handling.

Anyway -

… I didn’t get that … how should a log file look like?

If f:\ is a mapped network drive I’d recommend to run the script locally on the server where file are saved. This would speed up the script a lot.
Second - instead of using Out-File and catch everything I’d recommend using

to pick the properties you need and even maybe enrich the results and then output them with

to a CSV file.

A genereal tip …
Please always read the help for the cmdlets you’re about to use completely including the examples to learn how to use them.

Thanks all for the feedback. My apologies for the bad etiquette as a newbie.

I have figured out everything but, how to export out a list of empty directories. If I remove the export-csv option on the code below, it does display the results properly but, once I add the export-csv function back in, it does export but, exports the ‘length’ property rather than the directory name. I’m admittedly confused as to why/how that is happening as I don’t reference length at all. Any advice on what I’m missing?

$CurrentDate = Get-Date -Format "MM-dd-yyyy"
Get-ChildItem -Path F:\@backups -Recurse -Depth 2 -ErrorAction SilentlyContinue 
| Where-Object -FilterScript {($_.GetFiles().Count -eq 0) -and $_.GetDirectories().Count -eq 0} 
| Select-Object -ExpandProperty FullName 
| Export-Csv -NoTypeInformation -Path F:\@scripts\_logs\results-file-doesnt-exist_$CurrentDate.csv 

Your code would be a little easier to read if you added line breaks after each pipe symbol. :wink:

Instead of

... | 
Select-Object -ExpandProperty FullName |


... | 
Select-Object -Property FullName |

Umm, ok - thanks for the tip…