error message with a script sending emails to multiple recipients.


hi all,

i new powershell scripting , want request attention , on issue.

i getting error message "send-mailmessage: invalid character found in mail header: ','" given script:

param (  	[string]$path = "c:\temp\",  	[string]$smtpserver = "smtp.domain1.com",  	[string]$from = "sftpalert@domain.com",  	[string[]]$to = "mail_number1@domain1.com,mail_number2@domain1.com",  	[string]$subject = "new backup file"  	)    $smtpmessage = @{      = $to      = $from  	subject = "$subject @ $path"      smtpserver = $smtpserver  }    $file = get-childitem $path | { $_.lastwritetime -ge [datetime]::now.addhours(-6) }  if ($file)  {	$smtpbody = "`nthe following files have been added/changed:`n`n"  	$file | foreach { $smtpbody += "$($_.fullname)`n" }  	send-mailmessage @smtpmessage -body $smtpbody  	  }

found foreach() approach when put inside infinite loop.

many suggestions

[string[]]$to = "mail_number1@domain1.com,mail_number2@domain1.com",

should

[string[]]$to  = @("mail_number1@domain1.com","mail_number2@domain1.com")



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Azure MFA with Azure AD and RDS

Failed to setup initiator portal. Error status is given in the dump data.

Invalid pointer on gpresult /h gpreport.html