Credits goes to
I modified the script a little bit to pick up the log from c:\temp\ daily where the filename is made up of yyyymmdd
$a = Get-Date -Format yyyyMMdd
$smtpClient = new-object system.net.mail.smtpClient
$smtpClient.Host = 'smtp.gmail.com'
$smtpClient.Port = 587
$smtpClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("email@example.com", "password");
$emailFrom = "firstname.lastname@example.org"
$emailTo = "email@example.com,firstname.lastname@example.org"
$Subject = "Backup log for " +$a
$Body = "Please refer to attached logfile."
$emailMessage = New-Object System.Net.Mail.MailMessage
$emailMessage.From = $EmailFrom
$emailMessage.Subject = $Subject
$emailMessage.Body = $Body
For more information on Get-Date format, please click here
To get the SMART status of the hard disk with PowerShell, you could run the following:
Get-WmiObject win32_diskdrive|Select-Object Status
Below is a sample script to check multiple PC’s SMART status by getting a list of PC names from a text file.
$allComputers=Get-Content -Path C:\temp\pc.txt
foreach($computer in $allComputers)
$isonline=test-connection -Quiet -count 2 -ComputerName $computer
$diskStatus= Get-WmiObject win32_diskdrive -ComputerName $computer|Select-Object -ExpandProperty Status
Write-Host -ForegroundColor Green "$computer is online and disk status is $diskStatus";
Write-Host -ForegroundColor Red "$computer is offline";
For those of you who are interest in WMI programming, tools like WMI code Creator and Scriptomatic can be useful. The command wbemtest might come in handy sometimes as well but I find that WMI Explorers are more useful when you would like to know what classes are avaiable and when you would like to run and see what results does the Query produces.
I find the following three WMI Explorer to be very useful:
Happy programming 🙂