Checking file size gt 0 in Powershell

Question:

I did search for help regarding my subject but did not find something close to what I need, then here is my doubt:

I need to check the size of a file in a specific folder, if it´s greater than 0 bytes, it´s OK to continue the process, else, abort it writing an output message and sending fail code = 1.

I´ve tried the below but no success on writing the message to the log:

Does any of you know what I could do?

Appreciate your help!

Answer:

The code works absolutely fine. However make sure you provide an initial value to your “$rc”.

However, if you run the code again in the same scope, the value of the variable $rc will be 1. So make sure, you re-initialize the value to 0 or something else, so it might not produce a wrong result.

Source:

Checking file size gt 0 in Powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply