zoukankan      html  css  js  c++  java
  • 为Office365增加密码过期自动提醒功能

    最近有人和我反应,无法查看所有员工的Office365的密码过期时间。最好可以批量查看,如果能在过期前几天发个提醒邮件就更好了。

    $pw = ConvertTo-SecureString 'your_pwd' -AsPlainText -Force
    $creds = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist 'your_id@company.cn', $pw
    $mailpw = ConvertTo-SecureString 'your_pwd' -AsPlainText -Force
    $mailcreds = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist 'your_mail', $mailpw
    
    Connect-MsolService -Credential $creds
    $now = Get-Date
    #get-msoluser  | select UserPrincipalName, @{name='lastpasswordchangetimestamp';expression={$_.lastpasswordchangetimestamp.tostring().split(' ')[0]}} | Export-Csv -Path f:lastpasswordchangetimestamp.csv -Encoding Default
    
    $smtpserver = "your_smtp_server"
    $sender = "your_mail"
    $cc = "servicedesk@company.cn"
    $body = ‘
    <html><body>
    <h1>提醒</h1>
    您的Office 365账号密码即将过期,逾期不修改密码您将无法继续使用邮件功能。关于如何修改Office 365账号密码,请访问<a href="https://company.sharepoint.cn/IT/IT1/Office 365/如何更改office 365密码.docx?d=w6b52d070c5db4d518e76e726fffafbdc">这里</a>。
    </body></html>
    ’
    Get-MsolUser | select UserPrincipalName, @{name='delta';expression={($now - $_.lastpasswordchangetimestamp).days}} | foreach {
        if ($_.delta -ge 355) {
            $to = $_.UserPrincipalName
            $subject = "您的Office 365账号密码在" + (365 - $_.delta) + "天后即将过期,请及时修改!" 
            Send-MailMessage -SmtpServer $smtpserver -Credential $mailcreds -From $sender -To $to -Cc $cc -Subject $subject -Body $body -BodyAsHtml -Encoding default
            Write-Host $to, "mail sent!"
        }
    }
  • 相关阅读:
    SDOI2011古代朱文
    LIS 堆优化
    ZR2019 广州 游记
    LG2709 小B的询问
    [SCOI2009] 生日礼物
    [SDOI2008]沙拉公主的困惑
    [LG3396]哈希冲突
    ZROI2018.8.2 菜鸡互啄杯组队 ACM 赛
    ZROI 菜鸡互啄杯 III
    [LG4016] 负载平衡问题
  • 原文地址:https://www.cnblogs.com/IvanChen/p/5502258.html
Copyright © 2011-2022 走看看