Get the App
SLTechnology News&Howtos  ›  Servers  › 

Notify public mailbox accounts that they are about to expire and email notifications that have expired through powershell scripts

Shulou Source: shulou.com Published: 2022-06-02 15:50:18 11月13日 Update

#

# Author:Young, time: January 2018 # Email:azhe.911@foxmail.combr/ > # Email:azhe.911@foxmail.com

# Version:1.3

#

# Import active Directory powershell module

Import-Module Activedirectory

# current time

$TodayDate=Get-Date

# View the Samaccountname of all accounts in the specified OU

$Userlist=Get-ADUser-SearchBase "ou=test,dc=outlook,dc=com"-Filter * |% {$_ .Samsprintname}

# # #

# cycle to detect accounts that meet the Samaccountname,AccountExpirationDate,Manager attribute

# # #

Foreach ($user in $Userlist) {

$AccountExpirationDat=Get-ADUser $user-Properties Samaccountname,AccountExpirationDate,Manager,Enabled

# days from the expiration of the account

$expire_days= ($AccountExpirationDat.AccountExpirationDate-$TodayDate). Days

# the assignment is the email address of the public mail manager

$Manager= (Get-ADUser $AccountExpirationDat.Manager). UserPrincipalName

# the assignment is the name of the public mail manager $ManagerName= (Get-ADUser $AccountExpirationDat.Manager). The name # assigned to the public mail is $NameUser= (Get-ADUser $AccountExpirationDat.Samaccountname). Name

# retrieve those that contain the expiration time of the account and have the attribute of the manager (here it is worth the assignment of the manager in the organization in the attribute 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")

{

# verify the output accounts # $AccountExpirationDat# email body $Emailbady= "Hello, $ManagerName:

Your $NameUser public email account and $expire_days account will expire in a few days. Your account will be disabled after $expire_days days, which will affect the normal use of your public mailbox account. Please contact the help desk 010-10100120 as soon as possible to apply for the continued use of your public mailbox. Beijing xxxx Brokerage Co., Ltd. IT Department

"# represents the space IT Department this is to adjust the font size and color IT Department is to bold the font # send email to the public mail manager (manager) to notify Send-MailMessage-From" zhangsan@outlook.com "- to" $manager "- Subject" your public mailbox account is about to expire "- BodyAsHtml $Emailbady-SmtpServer mail.outlook.com-Encoding ([System.Text.Encoding]:: UTF8)}

# retrieve expired public mailbox accounts and send email notifications

Elseif ($AccountExpirationDat.AccountExpirationDate-and $AccountExpirationDat.Manager-and $expire_days-lt 0-and $AccountExpirationDat.Enabled-eq "True")

{

# verify the output accounts # $AccountExpirationDat# email body $Emailbady= "Hello, $ManagerName:

Your $NameUser public email account has expired $expire_days days. Your public mailbox account has been disabled, please confirm whether it still needs to be used, please contact the help desk 010-110101010 as soon as possible, if you need to continue to use, please submit an application for continued use, if the public mailbox is no longer in use, please submit an application to delete the account. Beijing xxxx Brokerage Co., Ltd. IT Department

"# represents the space IT Department this is to adjust the font size and color IT Department is to bold the font # send email to the public mail manager (manager) to notify Send-MailMessage-From" zhangsan@outlook.com "- to" $manager "- Subject" your public mailbox account has expired "- BodyAsHtml $Emailbady-SmtpServer mail.outlook.com-Encoding ([System.Text.Encoding]:: UTF8)}

}

Tags: Account mailbox mail manager font time personnel attributes management hello representative company size diva limited limited help desk text space color Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Huawei vpn MariaDB MySQL