· 9 years ago · Apr 20, 2017, 08:36 PM
1#Get the number of extensions sorted by count table, outout to a text file.
2NET USE R: \$IP\C$ /user:administrator password $folder1 = Get-Childitem directory | where { -not $_.PSIsContainer } | group Extension -NoElement | sort count -desc >> C:\Users\me\Desktop\DataFileCount.txt
3#My issue now is changing the array of the table into results I can add into the body of my email
4#I was thinking, if I am not able to break the array down into somthing readable to place in the email, I could send the results to a text file, then Get-Content the file and add that into the email.
5
6#Mail code
7$SMTPServer = "smtp.gmail.com"
8$SMTPPort = "587"
9$Username = "@gmail.com"
10$Password = "password"
11
12$to = "@.com"
13$cc = "@.com"
14$subject = "Mail Subject"
15$body = "(the table made above)"
16$attachment = ""
17
18$message = New-Object System.Net.Mail.MailMessage
19$message.subject = $subject
20$message.body = $body
21$message.to.add($to)
22$message.cc.add($cc)
23$message.from = $username
24$message.attachments.add($attachment)
25
26$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
27$smtp.EnableSSL = $true
28$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
29$smtp.send($message)