Sounds like you want a password generator.
A quick google search and this is the first result.
https://arminreiter.com/2021/07/3-ways-to-generate-passwords-in-powershell
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
"How can i get $password to set auto generated password rather than static"
$username = "John009"
$password = "password"
$computers = Get-Content c:\serverlist.txt
Foreach ($computer in $computers) {
$users = $null
$computer = [ADSI]“WinNT://$computer”
Try {
$users = $computer.psbase.children | Select-Object -expand name
if ($users -like $username) {
Write-Host "$username already exists"
} Else {
$user_obj = $computer.Create(“user”, “$username”)
$user_obj.SetPassword($password)
$user_obj.SetInfo()
$user_obj.Put(“description”, “$username”)
$user_obj.SetInfo()
$user_obj.psbase.invokeset(“AccountDisabled”, “False”)
$user_obj.SetInfo()
$users = $computer.psbase.children | Select-Object -expand name
if ($users -like $username) {
Write-Host "$username has been created on $($computer.name)"
} Else {
Write-Host "$username has not been created on $($computer.name)"
}
}
} Catch {
Write-Host "Error creating $username on $($computer.path): $($Error[0].Exception.Message)"
}
}
Sounds like you want a password generator.
A quick google search and this is the first result.
https://arminreiter.com/2021/07/3-ways-to-generate-passwords-in-powershell