diff options
author | mjfernez <mjf@mjfer.net> | 2022-02-19 15:35:26 -0500 |
---|---|---|
committer | mjfernez <mjf@mjfer.net> | 2022-02-19 15:35:26 -0500 |
commit | 2f463d02d70445f45a20f04787578ac937a6a4de (patch) | |
tree | aa44260e5955576ef745344babe65558a13dee78 /AD-powershell-tools/ad-bulk-reset.ps1 | |
parent | f47243fe63041008f1bb38fcf6de3549e31b7d8c (diff) | |
download | scripts-n-tools-2f463d02d70445f45a20f04787578ac937a6a4de.tar.gz |
Diffstat (limited to 'AD-powershell-tools/ad-bulk-reset.ps1')
-rw-r--r-- | AD-powershell-tools/ad-bulk-reset.ps1 | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/AD-powershell-tools/ad-bulk-reset.ps1 b/AD-powershell-tools/ad-bulk-reset.ps1 new file mode 100644 index 0000000..aa16515 --- /dev/null +++ b/AD-powershell-tools/ad-bulk-reset.ps1 @@ -0,0 +1,27 @@ +# Usage: ad-bulk-reset.ps1 <user-list-file>
+Import-Module ActiveDirectory
+
+function Gen-Random-Password {
+ $str = ""
+ for ($i = 0; $i -lt 24 ; $i++) {
+ $rand = Get-Random -Minimum 32 -Maximum 127
+ $str += [char]$rand
+ }
+ $newpwd = ConvertTo-SecureString -String [String]$str -AsPlainText -Force
+ return $newpwd
+}
+
+# Import users from CSV
+$csv = Get-Content $args[0]
+
+ForEach ($user in $csv) {
+ $newPassword = Gen-Random-Password
+
+ # Reset user password.
+ Set-ADAccountPassword -Identity $user -NewPassword $newPassword -Reset
+
+ # Force user to reset password at next logon.
+ # Remove this line if not needed for you
+ #Set-AdUser -Identity $user -ChangePasswordAtLogon $true
+ Write-Host $user"'s password has been reset"
+}
|