Advertisement
Guest User

scriptosten

a guest
Sep 20th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Param(
  2.     [parameter(Mandatory=$true)]
  3.     [alias("u")]
  4.     $username,
  5.  
  6.     [parameter(Mandatory=$true)]
  7.     [alias("fn")]
  8.     $fullname,
  9.  
  10.     [parameter(Mandatory=$true)]
  11.     [alias("desc")]
  12.     $description
  13. )
  14.  
  15. # Generate a random string
  16. Function Get-RandomAlphanumericString {
  17.    
  18.     [CmdletBinding()]
  19.     Param (
  20.         [int] $length = 8
  21.     )
  22.  
  23.     Begin{
  24.     }
  25.  
  26.     Process{
  27.         Write-Output ( -join ((0x30..0x39) + ( 0x41..0x5A) + ( 0x61..0x7A) | Get-Random -Count $length  | % {[char]$_}) )
  28.     }  
  29. }
  30.  
  31. # Instantiate a decoder object
  32. $encoder = New-Object System.Text.ASCIIEncoding
  33.  
  34. $password = $( Get-RandomAlphanumericString -length 10 )
  35. $key_str = $( Get-RandomAlphanumericString -length 32 )
  36.  
  37. $secure_password = ConvertTo-SecureString -String $password -AsplainText -Force
  38. $encrypted_password = ConvertFrom-SecureString -SecureString $secure_password
  39.  
  40. Write-Output "------------------------------------------------------"
  41. Write-Host "username = "$username
  42. Write-Host "password = "$password
  43. Write-Host "password encrypted: "$encrypted_password
  44. Write-Output "------------------------------------------------------"
  45.  
  46. # Create an account.
  47. New-LocalUser -AccountNeverExpires -Name $username -FullName $fullname -Password $secure_password -Description $description
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement