November 2, 2020 at 1:26 pm #267758
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
net use L: /d
November 2, 2020 at 1:43 pm #267773ParticipantTopics: 0Replies: 6Points: 31Rank: Member
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?
November 3, 2020 at 10:45 am #268856
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
November 3, 2020 at 11:10 am #268868
Nevermind. I think I got it. -Body “var1 var2”
At least it seems to be working.
- You must be logged in to reply to this topic.