Notify public mailbox accounts of expiring and overdue notifications via PowerShell script

Source: Internet
Author: User
Tags email account mail account mailmessage samaccountname

############################################

#Author: Young, Date: January 2018

#Email: [Email protected]

#For: Detect ad expiring/expired public accounts and email notifications

#Version: 1.2

##############################################

#导入活动目录powershell模块

Import-module ActiveDirectory

#当前时间

$TodayDate =get-date

#查看指定OU中的所有账户的Samaccountname

$Userlist =get-aduser-searchbase "ou=test,dc=lianjia,dc=com"-filter *? | %{$_. sAMAccountName}

#################################################

#循环检测满足Samaccountname, the account of the Accountexpirationdate,manager attribute

##################################################

foreach ($user in $Userlist) {

$AccountExpirationDat =get-aduser $user-properties? Samaccountname,accountexpirationdate,manager,enabled

#距离账户过期的时间天数

$expire _days= ($AccountExpirationDat. accountExpirationDate-$TodayDate). Days

#赋值是公邮经理的邮箱地址

$Manager = (Get-aduser $AccountExpirationDat. Manager). userPrincipalName

#赋值之公邮经理的名字

$ManagerName = (Get-aduser $AccountExpirationDat. Manager). Name

#赋值时公邮的邮名称

$NameUser = (Get-aduser $AccountExpirationDat. sAMAccountName). Name

#检索包含有快要账户过期时间的, and have management attributes (this is worth the assignment of managers in the organization in the properties of the public mail account)

if ($AccountExpirationDat. Accountexpirationdate-and $AccountExpirationDat. Manager-and $expire _days-ge 0-and $expire _days-le 15?? -and $AccountExpirationDat. Enabled-eq "True")

{

#验证输出的那些账户

# $AccountExpirationDat

#邮件正文

$Emailbady =

"Hello, $ManagerName:<p>

Your $NameUser public email account and $expire _days days will expire.? $expire _days days, your account will be disabled and will affect the normal use of your public email account, please contact <BR as soon as possible/>

Service desk 010-10109666 request permission to continue using your public mailbox. <br/>

Beijing Chain Home Real Estate Brokerage Co., Ltd. <br/>

IT department</p> "

#发送邮件给公邮管理人员 (manager) Mailbox notifications

Send-mailmessage-from "[email protected]"-to "$manager"-subject "Your public mailbox account is about to expire"-bodyashtml $Emailbady-smtpserver Mail . lianjia.com-encoding ([System.text.encoding]::utf8)

}

#检索已经过期的公共邮箱账户发送邮件通知

ElseIf ($AccountExpirationDat. Accountexpirationdate-and $AccountExpirationDat. Manager-and $expire _days-lt 0?-and $ Accountexpirationdat.enabled-eq "True")

{

#验证输出的那些账户

$AccountExpirationDat

#邮件正文

$Emailbady =

"Hello, $ManagerName:<p>

Your $NameUser public email account has expired $expire _days days.? Your public email account has been disabled please check if you still need to use, please contact the service <br/>

Taiwan 010-10109666 If you need to continue to use please submit an application for continued use, if the public mailbox is no longer used please submit a delete account request. <br/>

Beijing Chain Home Real Estate Brokerage Co., Ltd. <br/>

IT department</p> "

#发送邮件给公邮管理人员 (manager) Mailbox notifications

Send-mailmessage-from "[email protected]"-to "$manager"-subject "Your public email account has expired"-bodyashtml $Emailbady-smtpserver Mail . lianjia.com-encoding ([System.text.encoding]::utf8)

}

}

Notify public mailbox accounts of expiring and overdue notifications via PowerShell script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.