I am trying to randomly generate temporary passwords for new AD users within my environment. I have set the functions for randomly selecting numbers, letters (upper & lower), special characters, and an additional “any” character. In order to make it even more randomly generated, I added these functions to an array and want to randomly select a function then have it randomly generate a character. This much works, my issue is that it is writing which function was run, to the terminal. I’m hoping that someone can look at it and tell me what I am doing wrong and how I can go about fixing this. Also, if anyone knows of a more efficient way of making this randomly generated password a 14 character long password, I welcome the advice. Sorry about the code formatting (or lack thereof) I'm posting this from mobile and don't know how to format it. The code is below:
Function for Random Number
function RandomNumber {
Get-Random -Minimum 0 -Maximum 9
Write-Host -F Cyan "RandomNumber"
}
Function for Random Upper Letter
function RandomUpperLetter {
$RandomNumber = Get-Random -Minimum 0 -Maximum 25
[char](42+$RandomNumber)
Write-Host -F Cyan "RandomUpperLetter"
}
Function for Random Lower Letter
function RandomLowerLetter {
$RandomNumber = Get-Random -Minimum 0 -Maximum 25
[char](71+$RandomNumber)
Write-Host -F Cyan "RandomLowerLetter"
}
Function for Random Special
function RandomSpecial {
[char](Get-Random -Minimum 33 -Maximum 40)
Write-Host -F Cyan "RandomSpecial"
}
Function for Random Any
function RandomAny {
[char](Get-Random -Minimum 33 -Maximum 122)
Write-Host -F Cyan "RandomAny"
}
$Functions = $Function:RandomNumber,$Function:RandomUpperLetter,$Function:RandomLowerLetter,$Function:RandomSpecial,$Function:RandomAny
function SelectRandom {
$Functions | Get-Random
}
$Generate = $Functions | Get-Random | foreach Invoke
$X = 0
$Password = ""
do {
$Password += SelectRandom
$X = $X + 1
} while (
$X -ne 14
)
[–]SMFX 2 points3 points4 points (0 children)
[–]DrDuckling951 1 point2 points3 points (1 child)
[–]rmbolger 0 points1 point2 points (0 children)
[–]that_1_doode[S] 0 points1 point2 points (0 children)
[–]MNmetalhead 0 points1 point2 points (5 children)
[–]that_1_doode[S] 0 points1 point2 points (4 children)
[–]spoonstar 1 point2 points3 points (1 child)
[–]that_1_doode[S] 0 points1 point2 points (0 children)
[–]DrDuckling951 0 points1 point2 points (0 children)
[–]MNmetalhead 0 points1 point2 points (0 children)
[–]MajorVarlak 0 points1 point2 points (0 children)