Unable to find type [System Web Security Membership]

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
bush3102
Posts: 8
Joined: Thu Apr 05, 2018 7:24 am

Unable to find type [System Web Security Membership]

Post by bush3102 »

Powershell Studio Version: 2020
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
	
}

User avatar
bush3102
Posts: 8
Joined: Thu Apr 05, 2018 7:24 am

Re: Unable to find type [System Web Security Membership]

Post by bush3102 »

System.Web.DLL is not part of .NetCore and will not work with Powershell 7. So I have to create my own password generator.

jvierra
Posts: 14691
Joined: Tue May 22, 2007 9:57 am
Answers: 7
Has voted: 2 times
Been upvoted: 5 times

Re: Unable to find type [System Web Security Membership]

Post by jvierra »

PowerShell 7 does not support subsystems that are Windows only and should not be used except when it is necessary to run code on non-windows systems. The module will never be available on non-windows systems due to architecture differences and products. Tis module is for IIS and SharePoint only.

User avatar
bush3102
Posts: 8
Joined: Thu Apr 05, 2018 7:24 am

Re: Unable to find type [System Web Security Membership]

Post by bush3102 »

jvierra wrote:
Mon Aug 10, 2020 5:58 pm
PowerShell 7 does not support subsystems that are Windows only and should not be used except when it is necessary to run code on non-windows systems. The module will never be available on non-windows systems due to architecture differences and products. This module is for IIS and SharePoint only.
I was trying to use the Generate Password portion of System.Web. However, I went with the following password generator on GitHub.

Locked