With a number of searches I’ve put together a script that will email me a list of empty directories on our SAN. The email works, and sends me a rather ugly list on one line:
\sann\rdb$\RDT00437 \sann\rdb$\TEST0 \sann\rdb$\TEST1
When I try to pipe it to FORMAT-LIST I get garbage (times 3):
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
How can I format the list to look like:
\sann\rdb$\TEST0
\sann\rdb$\TEST1
\sann\rdb$\TEST2
Code:
$mailto2 = "space.manager@xxxxxx.com
$day_of_week = get-date -uformat “%A”
$empty_dir = get-childitem \sann\rdb$\ | Where-Object { $.PSIsContainer } |
Where-Object { $.GetFiles().Count -eq 0 } |
Where-Object { $.GetDirectories().Count -eq 0 } | ForEach-Object {$.FullName} | sort
$smtpServer = “yyyyyyy.xxxxxx.com”
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$msg = New-Object Net.Mail.MailMessage
$msg.From = “abc@xxxxxx.com”
$msg.Subject = $mailsubject + $day_of_week
$msg.IsBodyHTML = $false
$msg.Body = $empty_dir
$msg.To.Add($mailto2)
$smtp.Send($msg)