Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Powershell Management Series (39) PowerShell check

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

-provide Microsoft product implementation and outsourcing, such as AD\ Exchange\ Lync\ Sharepoint\ CRM\ SC\ O365, QQ:185426445. Tel. 18666943750

Requirements: according to the requirements of the group AD domain and subordinate 3 sub-domain statistics of all AD accounts, query all locked accounts, unlock, and send e-mail to the mailbox every morning.

Import-Module activedirectory$yuntcloud_Lockeduser = Search-ADAccount-LockedOut-SearchBase "dc=yuntcloud,dc=com"-server dc01 | select name, samaccountname$aaa_Lockeduser = Search-ADAccount-LockedOut-SearchBase "dc=aaa,dc=yuntcloud,dc=com"-server aaaDC1 | select name, samaccountname$bbb_Lockeduser = Search-ADAccount-LockedOut-SearchBase "dc=bbb,dc=yuntcloud,dc=com"-server bbbdc1 | select name, samaccountname$ccc_Lockeduser = Search-ADAccount-LockedOut-SearchBase "dc=ccc,dc=yuntcloud,dc=com"-server cccDC1 | select name Samaccountname#send email$UserName = "test01@yuntcloud.com" # define administrator account name $Password = ConvertTo-SecureString "Djds123"-AsPlainText-Force$cred = New-Object System.Management.Automation.PSCredential ($UserName $Password) $nFrom = "test01@yuntcloud.com" $nTo = "zhouping@yuntcloud.com" $lockeduser = @ () # Unlock yuntcloud Locked userif ([string]:: IsNullOrEmpty ($($yuntcloud_Lockeduser |% {$_ .name})) {Write-Host "yuntcloud no lockeduser" Start-Sleep 5 Send-MailMessage-From $nFrom-To $nTo-Subject "yuntcloud no lockeduser"-Body "yuntcloud no lockeduser"-Credential $cred-SmtpServer "mail.yuntcloud.com"-Encoding ([System.Text.Encoding]:: UTF8 )} else {Write-Host "yuntcloud Lockeduser" foreach ($I in $yuntcloud_Lockeduser) {Write-Host $i.name $lockeduser + = $I} Start-Sleep 5 Search-ADAccount-LockedOut-SearchBase "dc=yuntcloud Dc=com "- server dc01 | Unlock-ADAccount Write-Host" yuntcloud all locked account were unlocked "$lockeduser | Export-Csv-Path c:\ yuntcloud_lockeduser.csv-NoTypeInformation-Encoding utf8 Send-MailMessage-From $nfrom-To $nto-Subject" yuntcloud lockeduser "- Body" yuntcloud lockeduser "- Attachments" c:\ yuntcloud_lockeduser.csv "- Credential $cred-SmtpServer mail.yuntcloud.com-Encoding ([System.Text.Encoding]:: UTF8) Start-Sleep 3} # Unlock aaa.yuntcloud.com Locked user$lockeduser = @ ( ) if ([string]:: IsNullOrEmpty ($($aaa_Lockeduser |% {$_ .name})) {Write-Host "aaa no lockeduser" Start-Sleep 5 Send-MailMessage-From $nfrom-To $nto-Subject "aaa no lockeduser"-Body "aaa no lockeduser"-Credential $cred-SmtpServer mail.yuntcloud.com-Encoding ([System.Text.Encoding]:: UTF8)} else {Write-Host "aaa Lockeduser" foreach ($I in $aaa_Lockeduser) {Write-Host $i.name $lockeduser + = $I} Start-Sleep 5 Search-ADAccount-LockedOut-SearchBase "dc=aaa Dc=yuntcloud Dc=com "- server aaaDC1 | Unlock-ADAccount Write-Host" aaa all locked account were unlocked "$lockeduser | Export-Csv-Path c:\ aaa_lockeduser.csv-NoTypeInformation-Encoding utf8 Send-MailMessage-From $nfrom-To $nto-Subject" aaa lockeduser "- Body" aaa lockeduser "- Attachments" c:\ aaa_lockeduser.csv "- Credential $cred-SmtpServer mail.yuntcloud.com-Encoding ([System.Text.Encoding]:: UTF8) Start-Sleep 3} # Unlock bbb.yuntcloud.com Locked user$lockeduser = @ ( ) if ([string]:: IsNullOrEmpty ($($bbb_Lockeduser |% {$_ .name})) {Write-Host "bbb no lockeduser" Start-Sleep 5 Send-MailMessage-From $nfrom-To $nto-Subject "bbb no lockeduser"-Body "bbb no lockeduser"-Credential $cred-SmtpServer mail.yuntcloud.com-Encoding ([System.Text.Encoding]:: UTF8)} else {Write-Host "bbb Lockeduser" foreach ($I in $bbb_Lockeduser) {Write-Host $i.name $lockeduser + = $I} Start-Sleep 5 Search-ADAccount-LockedOut-SearchBase "dc=bbb Dc=yuntcloud Dc=com "- server bbbdc1 | Unlock-ADAccount Write-Host" bbb all locked account were unlocked "$lockeduser | Export-Csv-Path c:\ bbb_lockeduser.csv-NoTypeInformation-Encoding utf8 Send-MailMessage-From $nfrom-To $nto-Subject" bbb lockeduser "- Body" bbb lockeduser "- Attachments" c:\ bbb_lockeduser.csv "- Credential $cred-SmtpServer mail.yuntcloud.com-Encoding ([System.Text.Encoding]:: UTF8) Start-Sleep 3} # Unlock ccc.yuntcloud.com Locked user$lockeduser = @ ( ) if ([string]:: IsNullOrEmpty ($($ccc_Lockeduser |% {$_ .name})) {Write-Host "ccc no lockeduser" Start-Sleep 5 Send-MailMessage-From $nfrom-To $nto-Subject "ccc no lockeduser"-Body "ccc no lockeduser"-Credential $cred-SmtpServer mail.yuntcloud.com-Encoding ([System.Text.Encoding]:: UTF8)} else {Write-Host "ccc Lockeduser" foreach ($I in $ccc_Lockeduser) {Write-Host $i.name $lockeduser + = $I} Start-Sleep 5 Search-ADAccount-LockedOut-SearchBase "dc=ccc Dc=yuntcloud,dc=com "- server cccDC1 | Unlock-ADAccount Write-Host" ccc all locked account were unlocked "$lockeduser | Export-Csv-Path c:\ ccc_lockeduser.csv-NoTypeInformation-Encoding utf8 Send-MailMessage-From $nfrom-To $nto-Subject" ccc lockeduser "- Body" ccc lockeduser "- Attachments" c:\ ccc_lockeduser.csv "- Credential $cred-SmtpServer mail.yuntcloud.com-Encoding ([System.Text.Encoding]:: UTF8) Start-Sleep 3}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report