腳本1: 自動(dòng)導(dǎo)出用戶列表并重置密碼
####
# 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
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。