Powershell version: 7 - 64 bit
I have a button that I want to generate a random password using the following code that will show the password in a textbox for the user to see. However, when I run the script I get the following error message: Unable to find type (periods should be between words) [System Web Security Membership]
But this script works fine, in regular Powershell ISE version 5.1.
Code: Select all
$buttonGeneratePassword_Click={
#TODO: Place custom script here
add-type -AssemblyName System.Web -PassThru
$minLength = 15 ## characters
$maxLength = 25 ## characters
$length = Get-Random -Minimum $minLength -Maximum $maxLength
$nonAlphaChars = 5
$password = [System Web Security Membership]::GeneratePassword($length, $nonAlphaChars)
$txtbxPassword.Text = $password
}