I admit that I am a "rookie" when it comes to PowerShell. But I am hungry, and wanting to learn more. I have a thick, cumbersome PowerShell reference book here, but I am struggling to learn even the basic stuff.
So please forgive me for my following question.
I have the following script below. My goal is to:
a.) list the variables in the following script;
b.) define the Purpose of the following script.
$WMI = Get-WMIObject -Computer localhost -Class Win32_DiskDrive
$body = "URGENT Disk Report `n`n"
$allclear = ""
ForEach ($Drive in $WMI){
$body += $Drive.Caption + ": " + $Drive.Status + "`n"
if ($Drive.Status -ne "OK") { $allclear = "N" }
}
$date = Get-Date
$body += "`nExecuted at " + $date
if ($allclear -eq "N") {
$EmailFrom = "EMAIL ADDRESS"
$EmailTo = "EMAIL ADDRESS"
$Subject = "ISSUE DETECTED"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("USERNAME", "PASSWORD");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
}
else { Write-host "No Issues Detected" }
any help would be greatly appreciated.