1. 程式人生 > >通過powershell 腳本通知公共郵箱賬戶快要過期和已經過期郵件通知

通過powershell 腳本通知公共郵箱賬戶快要過期和已經過期郵件通知

hbase edi rsh earch 是否 郵箱 通過 組織 odin

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

#Author:Young,時間:2018年1月

#Email:[email protected]

#For:檢測AD快要過期/已經過期的公共賬戶並郵件通知

#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,AccountExpirationDate,Manager屬性的賬戶

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

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

#檢索包含有快要賬戶過期時間的、並有管理人員屬性的(這裏值得是公郵賬戶屬性中的組織中經理的賦值)

if($AccountExpirationDat.AccountExpirationDate -and $AccountExpirationDat.Manager -and $expire_days -ge 0 -and $expire_days -le 15?? -and $AccountExpirationDat.Enabled -eq "True" )

{

#驗證輸出的那些賬戶

#$AccountExpirationDat

#郵件正文

$Emailbady=

"您好, $ManagerName :<p>

您的 $NameUser 公共郵箱賬戶還有 $expire_days 天後就要過期了。? $expire_days 天後您的賬戶會被禁用將影響您這個公共郵箱賬戶的正常使用,請盡快聯系服<br />

務臺010-10109666申請您的公共郵箱繼續使用權限。 <br />

北京鏈家房地產經紀有限公司 <br />

IT Department</p> "

#發送郵件給公郵管理人員(經理)郵箱通知

Send-MailMessage -From "[email protected]" -to "$manager" -Subject "您的公共郵箱賬戶即將過期" -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=

"您好, $ManagerName :<p>

您的 $NameUser 公共郵箱賬戶已經過期 $expire_days 天了。? 您的公共郵箱賬戶已經禁用請確認一下是否還需要使用,請盡快聯系服務<br />

臺010-10109666如果需要繼續使用請提交一個繼續使用的申請,如果該公共郵箱不再使用請提交一個刪除賬戶的申請。 <br />

北京鏈家房地產經紀有限公司 <br />

IT Department</p> "

#發送郵件給公郵管理人員(經理)郵箱通知

Send-MailMessage -From "[email protected]" -to "$manager" -Subject "您的公共郵箱賬戶已經過期" -BodyAsHtml $Emailbady -SmtpServer mail.lianjia.com -Encoding ([System.Text.Encoding]::UTF8)

}

}

通過powershell 腳本通知公共郵箱賬戶快要過期和已經過期郵件通知