Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to add an embedded image to email?

$
0
0

Hi, I am completely stumped. I am trying to add an embedded image to notification email. The only scripts i can find are using .net to create a new email object.

#################################################
# Configure the following variables….
# expireindays1 + 2 = At what count of days left on a password do you want a notification?
$smtpServer=”smtp.yourmailserver.com”
$expireindays1 = 5
#$expireindays2 = 1
$from = “Name <name@yourmailserver.com>”
#################################################

#Get Users From AD who are enabled
Import-Module ActiveDirectory
$users = get-aduser -filter * -Properties enabled, GivenName, passwordneverexpires, passwordexpired, emailaddress, passwordlastset |where {$_.Enabled -eq “True”} | where { $_.PasswordNeverExpires -eq $false } | where { $_.passwordexpired -eq $false }

foreach ($user in $users)
{
$Name = (Get-ADUser $user | foreach { $_.Name})
$emailaddress = $user.emailaddress
$passwordSetDate = (get-aduser $user -properties passwordlastset | foreach { $_.PasswordLastSet })
$PasswordPol = (Get-AduserResultantPasswordPolicy $user)
# Check for Fine Grained Password
if (($PasswordPol) -ne $null)
{
$maxPasswordAge = ($PasswordPol).MaxPasswordAge
}

else
{
$maxPasswordAge = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge
}

$expireson = $passwordsetdate + $maxPasswordAge
$today = (get-date)
$daystoexpire = (New-TimeSpan -Start $today -End $Expireson).Days
$subject=”Your password will expire in $daystoExpire days”
$body =”
Dear $name,
<p> 
 Your password will expire in $daystoexpire day(s). After your password expires you will not be able to connect to the Infarmbureau network and will need to contact the Helpdesk.<br>

Please use the following steps below to change your password: <br>
- Press CTRL+ALT+DEL <br>
- On the next screen choose "Change password" <br>
- Verify that your UserID is correct, then type in your old and new passwords (be advised you cannot use one of your previously used passwords) <br>
- After the change is complete you will be prompted with information that your password has been changed <br>
- If you have a Mobile device such as laptop, cell phone, or Tablet, those passwords will need to be updated as well <br></P>”

if (($daystoexpire -eq $expireindays1))

# -or ($daystoexpire -eq $expireindays2))


{
Send-Mailmessage -smtpServer $smtpServer -from $from -to $emailaddress -subject $subject -body $body -bodyasHTML -priority High

}

}


Viewing all articles
Browse latest Browse all 21975

Trending Articles



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