Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Error "Send-MailMessage : An invalid character was found in the mail header: '@'."

$
0
0

I am trying to write the script to automate (using scheduler) departing AD user disabling.

Script I gobbled up:

"

$bfile = "C:\Temp\disable.bat"
$fromaddress = "<somegroup>@ssa.gov"
$user = Read-Host -Prompt "Please enter a username"
$usepath = Get-ADUser -Identity $user -Properties DistinguishedName | Select-Object DistinguishedName


$usepath -match "@{DistinguishedName=(?<content>.*)}"
$string = $matches
'dsmod user ' + $string['content'] + '-disabled yes' | Out-File -Filepath $bfile

$usemail = Get-ADUser -Identity $user -Properties mail | Select-Object mail
$usemail -match "@{mail=(?<content>.*)}" 
$string1 = $matches

$gname = Get-ADUser -Identity $user -Properties GivenName | Select-Object GivenName
$gname -match "GivenName=(?<content>.*)}"
$string2 = $matches
$string2 | Out-File -Filepath  $nfile


$properties = @{
    to         = "$usemail"
    from       = "$fromaddress"
    subject    = "Please remember to return SSA propery"
    smtpserver = "Dear $gname, Please remember to return SSA Badge, laptop and any other SSA property you might have"
}

Send-MailMessage @properties

"

First part works and successfully generates the batch file but email part throws an error: "Send-MailMessage : An invalid character was found in the mail header: '@'."

Please help!


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>