Advertisement
mfgwicked

Random password generator

Dec 17th, 2024 (edited)
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Invoke-RandomPassword {
  2.     <#
  3.     .SYNOPSIS
  4.     Calls random string of normal characters at any length noted by the length parameter.
  5.    
  6.     .DESCRIPTION
  7.     Injects 72 characters to the Get-Random CMDlet to produce a string, then converts the string to a secure string. Once converted, the Password is displayed on the host and copied to the clipboard.
  8.    
  9.     .PARAMETER Length
  10.     Use any length you see fit, no restriction. The default is 18 characters.
  11.    
  12.     .EXAMPLE
  13.     PS>Invoke-RandomPassword -Count 10
  14.    
  15.     #>
  16.         param(
  17.             [Parameter(Mandatory=$False)]
  18.             $Length=18
  19.         )
  20.         [array]$characters ='a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
  21.                             '1','2','3','4','5','6','7','8','9','0',
  22.                             'A','B','C','D','E','F','G','H','J','I','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
  23.                             '!','@','#','$','%','^','&','*','(',')'
  24.         $pw = ($characters | Get-Random -count $Length) -join ''
  25.         Write-Output $pw
  26.        
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement