There are several ways to create a random password in your PowerShell script.
Powershell function:
A function to create an random password string example:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-RandomPassword($length, $characters) { | |
$random = 1..$length | ForEach-Object { Get-Random -Maximum $characters.length } | |
$private:ofs="" | |
return [String]$characters[$random] | |
} | |
Get-RandomPassword -length 15 -characters "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#" |
Powershell script:
You can use a this script for more advanced functions:
GitHub - PowerShell random password generator
API:
You can use an API:
GitHub - fawazsullia/password-generator
Example:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url = 'https://passwordinator.herokuapp.com/generate?num=true&char=true&caps=true&len=14' | |
$password = (Invoke-WebRequest -Uri $url ).content | ConvertFrom-Json | |
$password.data |