使用powershell中的send-mailmessage 发送邮件提示无法连接服务器

各位大神好,我找了个powershell脚本想搜集域用户的密码到期时间,对快过期的用户发送邮件提醒更改密码:

在powershell里运行ok,但是保存成PS1的文件,右键运行就会弹错,
错误提示如下:

图片说明

求路过的大神帮忙看看,非常感谢!

代码如下:

Import-Module Activedirectory 
$alladuser=get-aduser -searchbase "OU=North,OU=andros_usr,DC=androsbj,DC=corp" -Filter 'PasswordNeverExpires -eq "false" -and enabled -eq "true"'  |ForEach{$_.SamAccountName}
foreach ($user in $alladuser){
$pwdlastset=Get-ADUser $user -Properties * |ForEach{$_.passwordlastset} 
$pwdlastday=($pwdlastset).adddays(90)
$now=get-date
$expire_days=($pwdlastday - $now).Days
if($expire_days -lt 100 ){    
    $chineseusername= Get-ADUser $user  -Properties * |ForEach{$_.Displayname} 
$Emailbody=    
@"    
<p class="MsoNormal" align="left" style="text-align: justify; margin: 0cm 0cm 0.0001pt;    
    font-size: 10.5pt; font-family: Calibri, sans-serif;">    
    <a name="_MailOriginal"><span lang="EN-US" style="font-size: 12.0pt; font-family: 宋体;    
        mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">您好, </span><span style="font-size: 12.0pt;    
            font-family: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">$chineseusername<span    
                lang="EN-US"> :</span></span>


<p class="MsoNormal" align="left" style="text-align: justify; margin: 0cm 0cm 0.0001pt;    
    font-size: 10.5pt; font-family: Calibri, sans-serif;">    
    <span style="font-size: 12.0pt; font-family: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">    
        &nbsp; &nbsp; 您的邮箱账户密码即将在<span lang="EN-US"> <font    
            color="#ff0000">$expire_days</font> </span>天后过期,<span lang="EN-US"> <font color="#ff0000">    
                $pwdlastday</font> </span>之后您将无法使用该账户登陆相关系统,请您尽快登录 https://mail.andros.com.cn/owa/ 更改帐号密码。</span>
<p class="MsoNormal" align="left" style="text-align: justify; margin: 0cm 0cm 0.0001pt;    
    font-size: 10.5pt; font-family: Calibri, sans-serif;">    
    <span style="font-size: 12.0pt; font-family: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">    
        &nbsp; &nbsp; 重置密码过程请遵循以下原则:</span>
<p class="MsoNormal" align="left" style="text-align: justify; margin: 0cm 0cm 0.0001pt;    
    font-size: 10.5pt; font-family: Calibri, sans-serif;">    
    <span style="font-family: 宋体; font-size: 16px; line-height: 24px; background-color: window;">    
        &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 16px; line-height: 24px;    
            background-color: window;">&nbsp;</span><span style="font-size: 12.0pt; font-family: 宋体;    
                mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><span lang="EN-US">1、</span>密码长度最少<span    
                    lang="EN-US">8</span>位,</span>密码中不能包含帐号信息;</span>
<p class="MsoNormal" align="left" style="text-align: justify; margin: 0cm 0cm 0.0001pt;    
    font-size: 10.5pt; font-family: Calibri, sans-serif;">    
    <span style="font-family: 宋体; font-size: 16px; line-height: 24px; background-color: window;">    
        &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 16px; line-height: 24px;    
            background-color: window;">&nbsp;</span><span style="font-size: 12.0pt; font-family: 宋体;    
                mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><span lang="EN-US">2、</span>密码可使用最长时间<span    
                    lang="EN-US">90</span>天,过期需要更改密码;</span>
<p class="MsoNormal" align="left" style="text-align: justify; margin: 0cm 0cm 0.0001pt;    
    font-size: 10.5pt; font-family: Calibri, sans-serif;">    
    <span style="font-family: 宋体; font-size: 16px; line-height: 24px; background-color: window;">    
        &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 16px; line-height: 24px;    
            background-color: window;">&nbsp;</span><span style="font-size: 12.0pt; font-family: 宋体;    
                mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><span lang="EN-US">3、</span>密码设置中必须包含:英文大写字母(A-Z),英文小字字母(a-z),10个基本数字(0-9),特殊字符(如!$ % ^ *等)。</span>
<p class="MsoNormal" align="left" style="text-align: justify; margin: 0cm 0cm 0.0001pt;    
    font-size: 10.5pt; font-family: Calibri, sans-serif;">    
    <span style="font-family: 宋体; font-size: 16px; line-height: 24px; background-color: window;">    
        &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 16px; line-height: 24px;    
            background-color: window;">&nbsp;</span><span style="font-size: 12.0pt; font-family: 宋体;    
                mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><span lang="EN-US">4、</span>强制密码历史<span    
                    lang="EN-US">1</span>个(不能使用之前最近使用的<span lang="EN-US">1</span>个密码);</span>
    <span style="font-family: 宋体; font-size: 16px; line-height: 24px; background-color: window;">    
        &nbsp; &nbsp;</span><span style="font-family: 宋体; font-size: 16px; line-height: 24px;    
            background-color: window;">&nbsp;</span><span style="font-size: 12.0pt; font-family: 宋体;    
                mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
<p class="MsoNormal" align="left" style="text-align: justify; margin: 0cm 0cm 0.0001pt;    
    font-size: 13px; font-family: Calibri, sans-serif;">    
    <span style="font-family: 宋体;"><span lang="EN-US"><font color="#969696">************************************************************************************************************************************************************************</font></span></span>
<p class="MsoNormal" align="left" style="text-align: justify; margin: 0cm 0cm 0.0001pt;    
    font-size: 13px; font-family: Calibri, sans-serif;">    
    <span style="font-family: 宋体;"><font color="#969696">系统自动提醒<span lang="EN-US">,</span>请不要回复<span    
        lang="EN-US">!</span>如有任何疑问,请联系itsupports@andros.com.cn</font></span>
"@
Send-MailMessage -To "liyanzhou@andros.com.cn" -Subject "您的域账户密码即将过期,请尽快更改!" -Bodyashtml $Emailbody -From "pwd@andros.com.cn"  -SmtpServer "mail.andros.com.cn" -Encoding ([System.Text.Encoding]::UTF8)
}}

在powershell里运行ok,但是保存成PS1的文件,右键运行就会弹错,错误提示如下:
图片说明
求路过的大神帮忙看看,非常感谢!

https://blog.csdn.net/weixin_33910759/article/details/92948968