![]() ![]() string password Guid.NewGuid().ToString('N').ToLower(). This code generates a 10 digit not-too-ugly password. Tweak as needed If you want a shorter string, change the number 100 in $i -lt 100 to the number you want. For a more humanistic random password generator I once implemented a prompt system using the EFF dice-word list. The code: $randomstring=for ($i=0 $i -lt 100 $i++) Notice: I have only tested my code on PowerShell 7, I guarantee my code will work, however I don't know if it will work on PowerShell 5.1. I can give you this simple code for this task. You can use PowerShell, it is now cross platform, you can download PowerShell 7 from GitHub. Install-Module $ModuleName -Force -Confirm:$false Get-Module -Name $ModuleName -ListAvailable | Uninstall-Module You can also install the password generator module $ModuleName = "RandomPasswordGenerator" $password | ConvertTo-SecureString -AsPlainText Until (($hasLowerChar + $hasUpperChar + $hasDigit + $hasSymbol) -ge 3) $hasSymbol = $password.IndexOfAny($symbols) -ne -1 ![]() $randomIndex = ::GetInt32(0, $characterList.Length) Here's one in Password generation in PowerShell Core (6+) $symbols = 'a'.'z' + 'A'.'Z' + '0'.'9' + $symbols NET Core does not support so it doesn't have ::GeneratePassword() and you'll have to write a custom a password generator or find some available code on the internet. In case you don't want to work with PowerShell then here's a pure batch solution
0 Comments
Leave a Reply. |