I have the Following script, and it outputs to a file just fine, but when it comes to emailing it, it says that the message body i get the following error:
Send-MailMessage : Cannot validate argument on parameter 'Body'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.here's my script
#Setting Date of One Week Back $week = (Get-Date).AddDays(-7) $today = (Get-Date).ToString() $style = @' <style> body { font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; color: #4f6b72; background: #E6EAE9; } a { color: #c75f3e; } #mytable { width: 700px; padding: 0; margin: 0; } caption { padding: 0 0 5px 0; width: 700px; font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; text-align: right; } th { font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; color: #4f6b72; border-right: 1px solid #C1DAD7; border-bottom: 1px solid #C1DAD7; border-top: 1px solid #C1DAD7; letter-spacing: 2px; text-transform: uppercase; text-align: left; padding: 6px 6px 6px 12px; background: #CAE8EA url(images/bg_header.jpg) no-repeat; } th.nobg { border-top: 0; border-left: 0; border-right: 1px solid #C1DAD7; background: none; } td { border-right: 1px solid #C1DAD7; border-bottom: 1px solid #C1DAD7; background: #fff; padding: 6px 6px 6px 12px; color: #4f6b72; } td.alt { background: #F5FAFA; color: #797268; } th.spec { border-left: 1px solid #C1DAD7; border-top: 0; background: #fff url(images/bullet1.gif) no-repeat; font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; } th.specalt { border-left: 1px solid #C1DAD7; border-top: 0; background: #f5fafa url(images/bullet2.gif) no-repeat; font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; color: #797268; }</style> '@ # Email Variables $smtp = "smtp.domain.com" $to = "group@domain.com" $from = "System Reports<guido.oliveira@domain.com>" $subject = "Recent Users and Groups Report" # Import Module of Active Directory Import-Module -Name ActiveDirectory # Run Command $Users = Get-ADUser -Filter * -Properties * | ` where { $_.whenCreated -ge $week } | Select-Object -Property @{ Name = 'Nome'; Expression = {$_.name} }, ` @{ Name = "Login" ; Expression = { $_.SamAccountName } }, ` @{ Name = "E-mail" ; Expression = { $_.mail }}, ` @{ Name = "Departamento" ; Expression = { $_.Department } }, ` @{ Name = "Unidade" ; Expression = { $_.Office } }, ` @{ Name = "Endereco" ; Expression = { $_.StreetAddress } }, ` @{ Name = "Empresa" ; Expression = { $_.Company } }, ` @{ Name = "Cidade" ; Expression = { $_.City } }, ` @{ Name = "Equipe" ; Expression = { $_.Description } }, ` @{ Name= "Criacao" ; Expression = { $_.WhenCreated }} ` | ConvertTo-html -PreContent "<H2>Usuarios criados nesta Semana.</H2>" -Fragment # Group $group = Get-ADgroup -Filter * -Properties * | ` where { $_.whenCreated -ge $week } | Select-Object -Property @{ Name = 'Nome'; Expression = {$_.name} }, ` @{ Name= "Criacao" ; Expression = { $_.WhenCreated }}, ` @{ Name = 'Nome'; Expression = {$_.name} }, ` @{ Name= "Descricao" ; Expression = { $_.Description }} ` | ConvertTo-html -PreContent "<H2>Grupos criados nesta Semana.</H2>" -Fragment # Folder $folders = Get-ChildItem -Path "\\netshoes.local\shares\work\Zona Compartilhada" -Attributes "Directory" | ` where { $_.CreationTime -ge $week } | Select-Object -Property @{ Name = 'Nome'; Expression = {$_.name} }, ` @{ Name= "Criacao" ; Expression = { $_.CreationTime }}, ` @{ Name = 'Caminho'; Expression = {$_.FullName} }, ` @{ Name = 'Proprietario'; Expression = {$_.Owner} } ` | ConvertTo-html -PreContent "<H2>Diretorios criados nesta Semana Na Zona Compartilhada.</H2>" -Fragment $btitle = "<H2>Periodo de criacao de $week a $today.</H2>" | ConvertTo-Html -Fragment $title = "<H1>Recent Users and Groups Report</H1>" | ConvertTo-Html -Fragment $message = ConvertTo-Html -Head $style -Body "$btitle $Users $group $folders" -Title "$title" -As Table $message Send-MailMessage -SmtpServer $smtp -To $to -Body $message -From $from -Subject $subject -BodyAsHtmlWhat am i missing