We’re moving to a new system on our public access computers that will require that staff provide a password for clients to login to the computers. Rather than training staff to change the password daily, I decided it would be easier to write a PowerShell script that runs as a Scheduled Task on the server every morning. It changes the password to one randomly selected from a word list (one word per line in a .txt file), and then writes the password to a file in a location only staff have access to so that they will know what it is.
To use this, copy the section below to a text file and save it as ChangePass.ps1 - note that you will need to allow scripts to be executed before this will work. Information about running .ps1 as a scheduled task is available here.
#Import the Active Directory Module
Import-Module ac*#Grabs a random line from WordList.txt (enter the full path, in quotes if the path contains a space)
$pwd = Get-Content C:\Script\WordList.txt | Get-Random#Uncomment the next line to print the selected password to the console
#Write-Host $pwd#Convert the selected password to a Secure String so it can be accepted by the commandlet
$secure = convertto-securestring $pwd -asplaintext -force#Set the password – replace username
Set-ADAccountPassword -Identity username -NewPassword $secure -reset#Write the password to a file so the staff will know what it is – add your own path
$pwd | Out-File “C:\Share\Todays Password.txt”
So when the script is down, the text file located in C:\Share (or whatever you’ve changed it to) will contain the password. Be aware that this file will be overwritten every time the script is run, so don’t edit the file – you’re changes will be lost.




