我完全難倒了。我正在嘗試向通知電子郵件中添加嵌入式圖像。我能找到的唯一腳本是使用.net創建一個新的電子郵件對象。只能使用.net創建電子郵件對象才能完成此操作。任何想法如何將嵌入式圖像添加到腳本?
#################################################
# Configure the following variables….
# expireindays1 + 2 = At what count of days left on a password do you want a notification?
$smtpServer=」smtprelay.domain.com」
$expireindays1 = 5
#$expireindays2 = 1
$from = 「Technology Helpdesk <[email protected]>」
#################################################
#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})
$UserID = (Get-ADUser $user -Properties *).Samaccountname
$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=
$body = @'
#<html>
<body>
<img src="cid:image1"><br>
<b>$UserID : Your password will expire soon</b>
<br>
<br>
<br>
Dear $name,<br>
Your password will expire in $daystoexpire days. Please change your password before it expires to avoid password related problems. .<br>
<br>
<br>
<b>Password complexity rules:<br>
<br>
- Must be 7 or 8 characters long<br>
- Must contain at least 1 uppercase letter<br>
- Must contain at least 1 lowercase letter<br>
- Must contain at least 1 number<br>
- Must NOT contain repeating characters (e.g., aa, 11)</b><br>
<br>
<br>
Please use the following steps to change your password:<br>
- Press CTRL+ALT+DEL<br>
- Click Change a password…<br>
- Verify your User ID is correct, then type in your old and new passwords (you cannot use previously used passwords)<br>
- After the change is complete, you will be prompted that your password has been changed<br>
- If you have a Blackberry, iPhone, or iPad, those devices will need your new password as soon as your password has been changed<br>
<br>
If you have questions, or need assistance updating your passwords, please contact the Technology Help Desk. <br>
</body>
#</html>
'@
if (($daystoexpire -eq $expireindays1))
# -or ($daystoexpire -eq $expireindays2))
{
#Send-Mailmessage -smtpServer $smtpServer -from $from -to [email protected] -subject $subject -body $body -bodyasHTML -priority High
####################################################################################################################
$images = @{
image1 = "c:\temp\action needed.png"
}
$params = @{
InlineAttachments = $images
#Attachments = 'C:\temp\action needed.png'
Body = $body
BodyAsHtml = $true
Subject = 」Your password will expire in $daystoExpire days」
From = "Technology Helpdesk <[email protected]>"
To = '[email protected]'
#Cc = '[email protected]', '[email protected]'
SmtpServer = 'smtprelay.domain.com'
}
Send-MailMessage @params
}
}
這有幫助嗎? http://winsysadm.net/send-mail-with-inline-embedded-images-with-powershell/ – Ernesto
幻影downvoters再次罷工。不要成爲一個匿名downvoter,說出來,讓人們可以改善他們的問題。 –
@ Ernesto,請添加爲答案而不是評論。這是一個有效的答案,但細節應列在這裏供將來參考。 –