Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module activedirectory
- # Create CSV file of users and passwords reset
- echo "User,Password" | Out-File -FilePath "C:\students.csv" -Append
- # Get list of users from an OU
- $Users = Get-ADUser -Filter * -Properties * -SearchBase "ou=students,ou=Schools,dc=contoso,dc=local"
- foreach ($user in $Users) {
- $username = $user.SAMACCOUNTNAME
- $keylist = @("a","A","b","B","c","C","d","D","f","F","g","G","M","P","q","Q","R","T","V","y","Y","z","Z","2","3","4","6","8")
- $pword = ""
- # Generate a simple password
- 1..6 | foreach $_ {
- $x = Get-Random -Minimum 0 -Maximum 30
- $pword += $keylist[$x]
- }
- # Output samaccount and password to file.
- echo "$username, $pword" | Out-File -FilePath "C:\students.csv" -Append
- #Apply passwords from csv file to user accounts in AD
- # "$File = import-csv -Path C:\students.csv"
- #foreach ($line in $File) {
- #$name = $line.Name
- #$pass = $line.Password
- $secstring = ConvertTo-SecureString -String $pword -AsPlainText -Force
- Set-ADAccountPassword -Identity $username -NewPassword $secstring -Reset
- }
Add Comment
Please, Sign In to add comment