locked
请问如何修改关于Password Expiry Email Notification的脚本? RRS feed

  • General discussion

  • 脚本的链接:https://gallery.technet.microsoft.com/scriptcenter/Password-Expiry-Email-177c3e27

    我大致浏览了一遍,有些能看懂并修改,但不确定格式是否正确。还有就是脚本怎么测试?需要在域账号上更改哪些东西后执行脚本才会触发?

    有可能我发送不了含有链接的帖子。

    Thursday, July 30, 2020 5:30 AM

All replies

  • 您好,

    感谢您访问我们的论坛,在这里我们主要关注有关Exchange服务器的一般问题,但是您的问题与脚本相关。 因此,我将您的主题移至脚本的专用论坛。

    https://social.technet.microsoft.com/forums/en-us/home?forum=ITCG&filter=alltypes&sort=lastpostdesc

    我们建议合理发布的原因是,您将获得更加专业的解决方案,而定期阅读论坛的其他合作伙伴可以分享他们的知识或从您与我们的互动中学习。感谢您的理解,并希望您的问题能尽快得到解决。

    此致,

    Lucas Liu


    如果以上回复对您有所帮助,建议您将其“标记为答复”. 如果您对我们的论坛支持有任何的建议,可以通过此邮箱联系我们:tnsf@microsoft.com.

    Thursday, July 30, 2020 8:29 AM
  • Hi, 

    you have examples in a script where described how to use it


    The opinion expressed by me is not an official position of Microsoft

    Thursday, July 30, 2020 11:32 AM
  • Sorry, but this forum is English only.

    -- Bill Stewart [Bill_Stewart]

    Thursday, July 30, 2020 7:33 PM
  • 在脚本专用论坛我也搜索到和我提出相同问题的帖子,但是我不确定脚本是否更改正确,以及如何测试脚本。
    Monday, August 10, 2020 8:31 AM
  • For some reason Kyle.Xy moved your question to the english forum, so would be great if you will write in english.

    At the same time hard to tell how and where you should test this script. Normally scripts tested in test enviroment. All needed command to do that described in the help message for this script. If you have error message you can post it here. Also would be great if you will write what you are expect, because from your comments its not clear. 


    The opinion expressed by me is not an official position of Microsoft

    Monday, August 10, 2020 8:56 AM
  • 你好!

    我在网上找了一段更实用的中文注解脚本,现在运行时遇到一些小问题。执行中的错误我先贴出来,然后脚本贴在下方(已去除注释)

    PS:很奇怪的是,在powershell ISE中运行该脚本会报以下错误,但最终可以正常执行完毕,也就是可以通过Send-Mailmessage中的BCC到我的邮箱。最后我将脚本放在任务计划中手动执行计划,却一直显示任务正在运行。

    错误:

    不能对 Null 值表达式调用方法。
    所在位置 D:\Mail-Attach\密码.ps1:26 字符: 1
    + $pwdlastday=$pwdlastset.adddays(90)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [],RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    脚本:

    $alladuser=get-aduser -searchbase "OU=contoso,DC=contoso,DC=com,DC=cn" -Filter {PasswordNeverExpires -eq "false" -and enabled -eq "true"} |ForEach{$_.SamAccountName}
    $userlist = @()
    foreach ($user in $alladuser){
    $pwdlastset=Get-ADUser $user -Properties * |ForEach{$_.passwordlastset}
    $useremail=Get-ADUser $user -Properties * |ForEach{$_.emailaddress}
    $pwdlastday=$pwdlastset.adddays(90)
    $now=get-date
    $expire_days=($pwdlastday - $now).Days
    if($expire_days -lt 7 ){
    $chineseusername= Get-ADUser $user -Properties * |ForEach{$_.name}
    $Emailbody=
    @"
    <p style="text-align: justify; margin: 0 0 0;font-size: 14px; font-family: Calibri, sans-serif;"><a name="_MailOriginal"></a><span style="font-size: 16px; font-family: 宋体; ">
    您好, $chineseusername :</span></p>
    <p style="text-align: justify; margin: 0 0 0;font-size: 14px; font-family: Calibri, sans-serif;">
    <span style="font-size: 16px; font-family: 宋体; ">
    您的邮箱账户密码即将在<span> <fontcolor="#ff0000">$expire_days</font> </span>天后过期,<span> <font color="#ff0000">$pwdlastday</font> </span>之后您将无法使用该账户登陆相关系统,请您登录以下地址尽快更改。</span></p>
    <p style="text-align: justify; margin: 0 0 0;font-size: 14px; font-family: Calibri, sans-serif;">
    <span style="font-size: 16px; font-family: 宋体; ">
    公司邮箱网页版地址:<a href="https://mail.contoso.com.cn/owa">https://mail.contoso.com.cn/owa</a></span></p>
    <p style="text-align: justify; margin: 0 0 0;font-size: 14px; font-family: Calibri, sans-serif;">
    <span style="font-size: 16px; font-family: 宋体; ">
    操作步骤:点击选项--常规--我的账户--更改帐号密码。</span></p>
    <p style="text-align: justify; margin: 0 0 0;font-size: 14px; font-family: Calibri, sans-serif;">
    <span style="font-size: 16px; font-family: 宋体; ">
    重置密码过程请遵循以下原则:</span></p>
    <p style="text-align: justify; margin: 0 0 0;font-size: 14px; font-family: Calibri, sans-serif;">
    <span style="font-family: 宋体; font-size: 16px; line-height: 24px;background-color: window;"></span>
    <span style="font-family: 宋体; font-size: 16px; line-height: 24px;background-color: window;"></span>
    <span style="font-size: 16px; font-family: 宋体; ">
    <span>1、</span>密码长度最少<span>7</span>位,密码中不能包含帐号信息;</span></p>
    <p style="text-align: justify; margin: 0 0 0;font-size: 14px; font-family: Calibri, sans-serif;"><span style="font-family: 宋体; font-size: 16px; line-height: 24px; background-color: window;"></span>
    <span style="font-family: 宋体; font-size: 16px; line-height: 24px;background-color: window;"></span>
    <span style="font-size: 16px; font-family: 宋体; ">
    <span>2、</span>密码可使用最长时间<span>90</span>天,过期需要更改密码;</span></p>
    <p style="text-align: justify; margin: 0 0 0;font-size: 14px; font-family: Calibri, sans-serif;"><span style="font-family: 宋体; font-size: 16px; line-height: 24px; background-color: window;"></span>
    <span style="font-family: 宋体; font-size: 16px; line-height: 24px;background-color: window;"> </span>
    <span style="font-size: 16px; font-family: 宋体; ">
    <span>3、</span>密码设置中必须包含:英文大写字母(A-Z),英文小字字母(a-z),10个基本数字(0-9),特殊字符(如!$ % ^ *等)四种符号中的任意三种;</span></p>
    <p style="text-align: justify; margin: 0 0 0;font-size: 14px; font-family: Calibri, sans-serif;"><span style="font-family: 宋体; font-size: 16px; line-height: 24px; background-color: window;"></span>
    <span style="font-family: 宋体; font-size: 16px; line-height: 24px;background-color: window;"> </span>
    <span style="font-size: 16px; font-family: 宋体; ">
    <span>4、</span>强制密码历史<span>1</span>个(不能使用之前最近使用的<span>1</span>个密码);</span></p>
    <p style="text-align: justify; margin: 0 0 0;font-size: 14px; font-family: Calibri, sans-serif;"><span style="font-family: 宋体; font-size: 16px; line-height: 24px; background-color: window;"></span>
    <span style="font-family: 宋体; font-size: 16px; line-height: 24px;background-color: window;"> </span>
    <span style="font-size: 16px; font-family: 宋体; ">
    <span>5、</span>不可包含部分或全部的用户名和旧密码。</span></p>
    <p style="text-align: justify; margin: 0 0 0;font-size: 13px; font-family: Calibri, sans-serif;">
    <span style="font-family: 宋体;"><span><font color="#969696">************************************************************************************************************************************************************************</font></span></span></p>
    <p style="text-align: justify; margin: 0 0 0;font-size: 13px; font-family: Calibri, sans-serif;">
    <span style="font-family: 宋体;"><font color="#969696">系统自动提醒<span>,</span>请不要回复<span>!</span>如有任何疑问,请联系itsupport@contoso.com.cn,IT支持电话:010-12345678</font></span></p>
    "@
    $anonUser = "itsupport@contoso.com.cn"
    $anonPass = ConvertTo-SecureString "password" -AsPlainText -Force
    sleep 3
    Send-Mailmessage -smtpServer "mail.contoso.com.cn" -from "itsupport@contoso.com.cn" -to $useremail -subject "您的域账户密码即将过期,请尽快更改!" -bcc "itsupport@contoso.com.cn" -body $Emailbody -bodyasHTML -Attachments "D:\邮箱密码未到期如何自行更改.docx" -priority High -Encoding ([System.Text.Encoding]::UTF8)
    }
    }
    exit


    • Edited by 纳兰炽羽 Wednesday, October 14, 2020 3:43 AM
    Wednesday, October 14, 2020 3:37 AM
  • 看来还是要靠自己啊。

    不能对 Null 值表达式调用方法。
    所在位置 D:\Mail-Attach\密码.ps1:26 字符: 1
    + $pwdlastday=$pwdlastset.adddays(90)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [],RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    $pwdlastday=$pwdlastset.adddays(90) 语句本身并没有任何错误,只是因为有一个或多个用户属性中“用户下次登录须更改密码”  这个打勾了(对应值 “pwdLastSet=0),导致“PasswordNeverExpires输出空值。

    只需在{PasswordNeverExpires -eq "false" -and enabled -eq "true"} 中添加一句 “pwdLastSet -ne “0” 

    来筛选 {永不过期=假 , enabled=真, 更改密码=非0}



    • Edited by 纳兰炽羽 Wednesday, October 14, 2020 8:58 AM
    Wednesday, October 14, 2020 8:57 AM
  • $pwdlastset=Get-ADUser $user -Properties * |ForEach{$_.passwordlastset}

    this command return nothing


    The opinion expressed by me is not an official position of Microsoft

    Wednesday, October 14, 2020 10:04 AM