Check file size and take desired action

%3CLINGO-SUB%20id%3D%22lingo-sub-1416161%22%20slang%3D%22en-US%22%3ECheck%20file%20size%20and%20take%20desired%20action%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1416161%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20location%20where%20a%20software%20saves%20an%20Excel%20File%20for%20me.%20(%20I%20control%20the%20location%2C%20time%20and%20other%20things)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20powershell%20script%20already%20that%20emails%20this%20file%20to%20my%20Outlook%20Groups.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20to%20see%20if%20i%20can%20add%20another%20code%20before%20emailing%20which%20compares%2Fanalysis%20the%20size%20of%20the%20file%20%2C%20lets%20say%20the%20file%20is%20500%20BYtes%20(%20no%20data%20in%20the%20file)%20%2C%20then%20do%20not%20email%20or%20the%20next%20code%20doesn't%20execute%2F%3CBR%20%2F%3Eif%20it%20is%20more%20than%20500%20bytes%2C%20then%20yes%2C%20execute%20the%20next%20line%20of%20code.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1416161%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1417209%22%20slang%3D%22en-US%22%3ERe%3A%20Check%20file%20size%20and%20take%20desired%20action%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1417209%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F156230%22%20target%3D%22_blank%22%3E%40ankit%20shukla%3C%2FA%3E%26nbsp%3BYou%20can%20do%20something%20like%20this%3A%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-ChildItem%20%7C%20where%20%7B%20(-NOT%20%24_.PSIsContainer)%20-and%20(%24_.Length%20-gt%200.5KB)%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EGood%20luck%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGrtz%2C%20Manfred%20de%20Laat%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1494932%22%20slang%3D%22en-US%22%3ERe%3A%20Check%20file%20size%20and%20take%20desired%20action%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1494932%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F156230%22%20target%3D%22_blank%22%3E%40ankit%20shukla%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Esomething%20like%20this%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Eif%20((dir%20c%3A%5Ctemp%5CyourExcelfile.xlsx%20).Length%20-gt%20500)%20%7B%22do%20hard%20work%20to%20sen%20the%20e-mail%22%7D%0A%23or%0A(dir%20*.xlsx%20-file)%7C%0A%20%20%20%20%20%3F%7B%20%24_.Length%20-gt%20500%7D%7C%0A%20%20%20%20%20%20%20%20%20%25%7B%22Is%20greater%20do%20hard%20work%20to%20send%20the%20e-mail%20with%20file%20%24(%24_.fullname)%22%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Frequent Contributor

I have location where a software saves an Excel File for me. ( I control the location, time and other things)

 

I have a powershell script already that emails this file to my Outlook Groups.

 

I need to see if i can add another code before emailing which compares/analysis the size of the file , lets say the file is 500 BYtes ( no data in the file) , then do not email or the next code doesn't execute/
if it is more than 500 bytes, then yes, execute the next line of code.

2 Replies
Highlighted

@ankit shukla You can do something like this: 

Get-ChildItem | where { (-NOT $_.PSIsContainer) -and ($_.Length -gt 0.5KB) }

Good luck

 

Grtz, Manfred de Laat 

@ankit shukla 

something like this

 

 

if ((dir c:\temp\yourExcelfile.xlsx ).Length -gt 500) {"do hard work to sen the e-mail"}
#or
(dir *.xlsx -file)|
     ?{ $_.Length -gt 500}|
         %{"Is greater do hard work to send the e-mail with file $($_.fullname)"}