脚本1: 自动导出用户列表并重置密码
####
# bulk reset user password
###
$path = Split-Path -parent $MyInvocation.MyCommand.Definition
$tmppath = $path + "\users.csv"
$log = $path + "\reset_pwd.v2.log"
$pass = "new_password"
$date = Get-Date
"Processing started (on " + $date + "): " | Out-File $log -append
"--------------------------------------------" | Out-File $log -append
# export AD Users
# with all properties, and actived
# get-aduser -filter * -properties * | where {$_.enabled -eq $false} |export-csv $tmppath -Encoding UTF8 -NoType
Get-Aduser -filter * | Where {$_.enabled -eq $true} |Export-Csv $tmppath -Encoding UTF8 -NoType
# reset password
Write-Host "[INFO]`t Reset Password As : $pass"
Import-Csv -Path $tmppath | ForEach-Object {
Write-Host "[INFO]`t Reset Password For User : $($_.Name) "
Try
{
# Set-ADAccountPassword $_.DistinguishedName -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $pass -Force)
# Set-ADUser -ChangePasswordAtLogon $false $_.DistinguishedName
"[INFO]`t User $($_.Name) password reseted!" | Out-File $log -append
}
Catch
{
Write-Host "[ERROR]`t Oops, something went wrong: $($_.Exception.Message)`r`n"
"$($_.Exception.Message)" | Out-File $log -append
}
}
"--------------------------------------------" + "`r`n" | Out-File $log -append
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。