Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[System.Web.Security.Membership]::GeneratePassword() - Type Not found

Why do I get Type Not Found when trying to use this class/method in PowerShell?

 [System.Web.Security.Membership]::GeneratePassword()

Do I need to install a module or something to make use of it?

like image 226
Rakha Avatar asked Nov 14 '18 19:11

Rakha


2 Answers

For those landing here who are using PowerShell Core, as per this link:

https://github.com/PowerShell/PowerShell/issues/5352

.NET Core does not support System.Web.dll

As such [System.Web.Security.Membership]::GeneratePassword() will result in the same Type Not Found error in PowerShell Core even with the add-type fix above.

You'll have to roll your own password generator.

like image 53
DefChip Avatar answered Nov 18 '22 03:11

DefChip


Load the assembly first:

add-type -AssemblyName System.Web
[System.Web.Security.Membership]::GeneratePassword(10,0)
like image 20
Rakha Avatar answered Nov 18 '22 03:11

Rakha