Powershell管理系列(四十)PowerShell查询
发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,-----提供AD\Exchange\Lync\Sharepoint\CRM\SC\O365等微软产品实施及外包,QQ:185426445.电话18666943750需求:根据要求对集团AD域及下属3
千家信息网最后更新 2025年01月20日Powershell管理系列(四十)PowerShell查询
-----提供AD\Exchange\Lync\Sharepoint\CRM\SC\O365等微软产品实施及外包,QQ:185426445.电话18666943750
需求:根据要求对集团AD域及下属3个子域的所有AD账号进行统计,查询所有锁定的账号,解锁,并每天早上发送邮件到指向邮箱。(之前三十九的基础上略作调整,只发一封邮件即可)
Remove-Item C:\get_locked_user\ -Recurse -Forceif(!(test-path C:\get_locked_user)) {New-Item C:\get_locked_user -type directory}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 "Anvf20170708" -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 5Set-Content C:\get_locked_user\locked.txt -Value "yuntcloud no locked user"#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 5Search-ADAccount -LockedOut -SearchBase "dc=yuntcloud,dc=com" -server dc01 |Unlock-ADAccountWrite-Host "yuntcloud all locked account were unlocked"$lockeduser |Export-Csv -Path C:\get_locked_user\yuntcloud_lockeduser.csv -NoTypeInformation -Encoding utf8 add-Content C:\get_locked_user\locked.txt -Value "yuntcloud Locked user"add-Content C:\get_locked_user\locked.txt -Value $($yuntcloud_Lockeduser|%{$_.name})#Send-MailMessage -From $nfrom -To $nto -Subject "yuntcloud locked user" -Body "yuntcloud locked user" -Attachments "C:\get_locked_user\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 5add-Content C:\get_locked_user\locked.txt -Value "aaa no locked user"#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 5Search-ADAccount -LockedOut -SearchBase "dc=aaa,dc=yuntcloud,dc=com" -server aaaDC1 |Unlock-ADAccountWrite-Host "aaa all locked account were unlocked" $lockeduser |Export-Csv -Path C:\get_locked_user\aaa_lockeduser.csv -NoTypeInformation -Encoding utf8add-Content C:\get_locked_user\locked.txt -Value "aaa Locked user"add-Content C:\get_locked_user\locked.txt -Value $($aaa_Lockeduser|%{$_.name})#Send-MailMessage -From $nfrom -To $nto -Subject "aaa locked user" -Body "aaa locked user" -Attachments "C:\get_locked_user\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 5add-Content C:\get_locked_user\locked.txt -Value "bbb no locked user"#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 5Search-ADAccount -LockedOut -SearchBase "dc=bbb,dc=yuntcloud,dc=com" -server bbbdc1 |Unlock-ADAccountWrite-Host "bbb all locked account were unlocked" $lockeduser |Export-Csv -Path C:\get_locked_user\bbb_lockeduser.csv -NoTypeInformation -Encoding utf8 add-Content C:\get_locked_user\locked.txt -Value "bbb Locked user"add-Content C:\get_locked_user\locked.txt -Value $($bbb_Lockeduser|%{$_.name})#Send-MailMessage -From $nfrom -To $nto -Subject "bbb locked user" -Body "bbb locked user" -Attachments "C:\get_locked_user\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 5add-Content C:\get_locked_user\locked.txt -Value "ccc no locked user"#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 5Search-ADAccount -LockedOut -SearchBase "dc=ccc,dc=yuntcloud,dc=com" -server cccDC1 |Unlock-ADAccountWrite-Host "ccc all locked account were unlocked" $lockeduser |Export-Csv -Path C:\get_locked_user\ccc_lockeduser.csv -NoTypeInformation -Encoding utf8 add-Content C:\get_locked_user\locked.txt -Value "ccc Locked user"add-Content C:\get_locked_user\locked.txt -Value $($ccc_Lockeduser|%{$_.name})#Send-MailMessage -From $nfrom -To $nto -Subject "ccc locked user" -Body "ccc locked user" -Attachments "C:\get_locked_user\ccc_lockeduser.csv" -Credential $cred -SmtpServer mail.yuntcloud.com -Encoding ([System.Text.Encoding]::UTF8) Start-Sleep 3}$body=get-Content C:\get_locked_user\locked.txt|Out-Stringif (((Test-Path C:\get_locked_user\yuntcloud_lockeduser.csv) -eq $true) -and ((Test-Path C:\get_locked_user\aaa_lockeduser.csv) -eq $false) -and ((Test-Path C:\get_locked_user\bbb_lockeduser.csv) -eq $false) -and ((Test-Path C:\get_locked_user\ccc_lockeduser.csv) -eq $false)) {Send-MailMessage -From $nfrom -To $nto -Subject "yuntcloud 4 domains all locked user information total" -Body $body -Attachments "C:\get_locked_user\yuntcloud_lockeduser.csv" -Credential $cred -SmtpServer mail.yuntcloud.com -Encoding ([System.Text.Encoding]::UTF8) }elseif (((Test-Path C:\get_locked_user\yuntcloud_lockeduser.csv) -eq $true) -and ((Test-Path C:\get_locked_user\aaa_lockeduser.csv) -eq $true) -and ((Test-Path C:\get_locked_user\bbb_lockeduser.csv) -eq $false) -and ((Test-Path C:\get_locked_user\ccc_lockeduser.csv) -eq $false)) {Send-MailMessage -From $nfrom -To $nto -Subject "yuntcloud 4 domains all locked user information total" -Body $body -Attachments "C:\get_locked_user\yuntcloud_lockeduser.csv","C:\get_locked_user\aaa_lockeduser.csv" -Credential $cred -SmtpServer mail.yuntcloud.com -Encoding ([System.Text.Encoding]::UTF8) }elseif (((Test-Path C:\get_locked_user\yuntcloud_lockeduser.csv) -eq $true) -and ((Test-Path C:\get_locked_user\aaa_lockeduser.csv) -eq $true) -and ((Test-Path C:\get_locked_user\bbb_lockeduser.csv) -eq $true) -and ((Test-Path C:\get_locked_user\ccc_lockeduser.csv) -eq $false)) {Send-MailMessage -From $nfrom -To $nto -Subject "yuntcloud 4 domains all locked user information total" -Body $body -Attachments "C:\get_locked_user\yuntcloud_lockeduser.csv","C:\get_locked_user\aaa_lockeduser.csv","C:\get_locked_user\bbb_lockeduser.csv" -Credential $cred -SmtpServer mail.yuntcloud.com -Encoding ([System.Text.Encoding]::UTF8) }elseif (((Test-Path C:\get_locked_user\yuntcloud_lockeduser.csv) -eq $true) -and ((Test-Path C:\get_locked_user\aaa_lockeduser.csv) -eq $true) -and ((Test-Path C:\get_locked_user\bbb_lockeduser.csv) -eq $true) -and ((Test-Path C:\get_locked_user\ccc_lockeduser.csv) -eq $true)) {Send-MailMessage -From $nfrom -To $nto -Subject "yuntcloud 4 domains all locked user information total" -Body $body -Attachments "C:\get_locked_user\yuntcloud_lockeduser.csv","C:\get_locked_user\aaa_lockeduser.csv","C:\get_locked_user\bbb_lockeduser.csv","C:\get_locked_user\ccc_lockeduser.csv" -Credential $cred -SmtpServer mail.yuntcloud.com -Encoding ([System.Text.Encoding]::UTF8) }else{Send-MailMessage -From $nfrom -To $nto -Subject "yuntcloud 4 domains all locked user information total" -Body $body -Credential $cred -SmtpServer mail.yuntcloud.com -Encoding ([System.Text.Encoding]::UTF8) }
账号
邮件
查询
管理
个子
产品
名称
基础
指向
电话
管理员
账户
邮箱
集团
需求
微软
统计
调整
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
易语言数据库删除指定记录
服务器显示0A是什么意思
川师2016数据库
数据库支持流数据
清理泰拉瑞亚云服务器
网络安全法特性
电脑共享网络输入网络安全密钥
软件开发直属转外包
独立服务器十大功能
局域网服务器可以用光纤连接吗
网络技术服务合同审核
网络技术毕业设计200字
计算机网络技术应用ppt课件
计算机网络技术宣传
碧蓝档案现在有几个服务器
云服务器的实例名称是什么
区域授权服务器
教学平台软件开发方案
南昌大学网络安全与信息科技大赛
崇明区智能化软件开发服务价钱
选择当前数据库的语法
国际棋联fide的数据库
新融合服务器
网络安全黑白的手抄报
大数据与网络安全概念
数据库怎么把null转变为空值
数据库和网络其他系统的通信
数据库new是什么意思
中山市卡迅网络技术有限公司
外挂软件开发原理