Count files after Get-ChildItem

I have been trying to just get what would look like he contents of a directory when using the simple “dir” command, but have had no luck. The below is close, but is not showing my how many files are in the directory. I tried to figure out how to use the Measure-Object cmdlet, but only wound up breaking the ability to Send the mail message. Can someone assist me with getting a directory and its contents emailed to me which includes the number of files? Sorry … I tried to get the below code into a code box, but not sure what I was doing wrong. It came out all in one long line.

 

net use L: \system1-NA-01\RTC\Production

$body = Get-ChildItem -Path L:\ | Out-String

Send-MailMessage -From noreply@ide.ddd.net -Subject “Cleanup Results” `

-To admins@ide.ddd.net -Body $body `

-SmtpServer vex03.ide.ddd.net

net use L: /d

Hi geelsu02,

 

One way to get the number of files in L:\ could be:

(Get-ChildItem -Path L:\ -File).count

 

If you wanted to also count the files in the subdirectories, you could use the Recurse option of the get-ChildItem cmdlet:

(Get-ChildItem -Path L:\ -File -Recurse).count

 

Does that help?

Thank you cdmenge. I will give that a try. Would you happen to know how to include TWO variables when using -Body while using the Send-MailMessage cmdlet.

Send-MailMessage -Body var1, var2

Nevermind. I think I got it. -Body “var1 var2”

 

At least it seems to be working.