Count files after Get-ChildItem

Welcome Forums General PowerShell Q&A Count files after Get-ChildItem

Viewing 3 reply threads
  • Author
    Posts
    • #267758
      Participant
      Topics: 2
      Replies: 5
      Points: 29
      Rank: Member

      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 [email protected] -Subject “Cleanup Results”

      -To [email protected] -Body $body

      -SmtpServer vex03.ide.ddd.net

      net use L:   /d

    • #267773
      Participant
      Topics: 0
      Replies: 6
      Points: 31
      Rank: Member

      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?

    • #268856
      Participant
      Topics: 2
      Replies: 5
      Points: 29
      Rank: Member

      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
    • #268868
      Participant
      Topics: 2
      Replies: 5
      Points: 29
      Rank: Member

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

       

      At least it seems to be working.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.