Powershell管理系列(三十九)PowerShell查
发表于:2025-01-25 作者:千家信息网编辑
千家信息网最后更新 2025年01月25日,-----提供AD\Exchange\Lync\Sharepoint\CRM\SC\O365等微软产品实施及外包,QQ:185426445.电话18666943750需求:根据要求对集团AD域及下属3
千家信息网最后更新 2025年01月25日Powershell管理系列(三十九)PowerShell查
-----提供AD\Exchange\Lync\Sharepoint\CRM\SC\O365等微软产品实施及外包,QQ:185426445.电话18666943750
需求:根据要求对集团AD域及下属3个子域的所有AD账号进行统计,查询所有锁定的账号,解锁,并每天早上发送邮件到指向邮箱。
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" #定义管理员账户名称$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 locked user" Start-Sleep 5 Send-MailMessage -From $nFrom -To $nTo -Subject "yuntcloud no locked user" -Body "yuntcloud no locked user" -Credential $cred -SmtpServer "mail.yuntcloud.com" -Encoding ([System.Text.Encoding]::UTF8)}else{ Write-Host "yuntcloud Locked user" 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 locked user" -Body "yuntcloud locked user" -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 locked user" Start-Sleep 5 Send-MailMessage -From $nfrom -To $nto -Subject "aaa no locked user" -Body "aaa no locked user" -Credential $cred -SmtpServer mail.yuntcloud.com -Encoding ([System.Text.Encoding]::UTF8)}else{ Write-Host "aaa Locked user" 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 locked user" -Body "aaa locked user" -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 locked user" Start-Sleep 5 Send-MailMessage -From $nfrom -To $nto -Subject "bbb no locked user" -Body "bbb no locked user" -Credential $cred -SmtpServer mail.yuntcloud.com -Encoding ([System.Text.Encoding]::UTF8)}else{ Write-Host "bbb Locked user" 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 locked user" -Body "bbb locked user" -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 locked user" Start-Sleep 5 Send-MailMessage -From $nfrom -To $nto -Subject "ccc no locked user" -Body "ccc no locked user" -Credential $cred -SmtpServer mail.yuntcloud.com -Encoding ([System.Text.Encoding]::UTF8)}else{ Write-Host "ccc Locked user" 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 locked user" -Body "ccc locked user" -Attachments "c:\ccc_lockeduser.csv" -Credential $cred -SmtpServer mail.yuntcloud.com -Encoding ([System.Text.Encoding]::UTF8) Start-Sleep 3}
账号
管理
个子
产品
名称
指向
电话
管理员
账户
邮件
邮箱
集团
需求
微软
查询
统计
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发多少税率
服务器电源输出多少伏
网络安全技术防护
从数据库a访问数据库b
中国省市区名的数据库
网络安全水分太大
计算机网络技术工程学院
pg数据库配置文件路径
广州金钟网络技术有限公司
网络安全在身边作文500字
网络技术三级应用题
中国联机服务器推荐
淘宝买家数据库下载
北京ai教育系统开发软件开发
什么样的中小企业能用到服务器
我国网络安全治理的目标
平度系统软件开发
pubg哪个服务器中国人比较多
郑州科技软件开发公司排名
网络安全哪个方向工资高
力控数据库怎么恢复
校园网络安全广告语大全
藏汉语网络安全讲解
苏州市网络安全宣传周开放日
数据库单选试题
简述数据库与文件系统
云服务器上安装编程软件吗
智能农业软件开发
荆州农科院 网络安全
服务器测试面试题