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.
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.
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.
… 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?