Function sendEmail
{
param($to)
# Sender and Recipient Info
$MailFrom = "xxx@xxx.com"
$MailTo = "xxx@xxx.com"
$MailTo = "xxx@xxx.com"
# Sender Credentials
$Username = "xxx@xxx.com"
$Password = "xxx"
# Server Info
$SmtpServer = "smtp.gmail.com"
$SmtpPort = "587"
# Message stuff
$MessageSubject = $to
$Message = New-Object System.Net.Mail.MailMessage $MailFrom,$MailTo
$Message.IsBodyHTML = $true
$Message.Subject = $MessageSubject
$Message.Body = @'
<!DOCTYPE html>
<html>
<head>
</head>
<body>
MENSAGEM ENVIADA SOBRE O SERVIDOR.
</body>
</html>
'@
# Construct the SMTP client object, credentials, and send
$Smtp = New-Object Net.Mail.SmtpClient($SmtpServer,$SmtpPort)
$Smtp.EnableSsl = $true
$Smtp.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)
$Smtp.Send($Message)
}
# Get SQL Server hostname
$hostname=Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty name
# Here I need Get all drives include network drives mapped. How to do it ?
$Results = Get-WMIObject -ComputerName $hostname Win32_LogicalDisk | where {($_.DriveType -eq 3)}
ForEach ($Result In $Results)
{
$drive = $Result.Name
$space = $Result.FreeSpace
$size = $Result.Size
if((($space/1gb)/($size/1gb)) -le 0.901){
$espacoLivre = ("{0:N0}" -f [math]::truncate($space/1GB))
$espacoTotal = ("{0:N0}" -f [math]::truncate($size/1GB))
$espacoLivre = $espacoLivre + " GB"
$espacoTotal = $espacoTotal + " GB"
$mensagem = $hostname + " " + $drive + " " + $espacoLivre + " livres de " + $espacoTotal + " total."
sendEmail $mensagem
}
}
Someone can help me ?
This code above show only hard disk in the server.
I need to show network locations whith total space and used space.
Have you searched for enumerating network drives?
Also, there are easier ways to build HTML in Powershell, take a look at:
thanks