Sometimes, small series need a random password. When writing ASP, generate with ASP, write C # when using C # generation. C # can be used in PowerShell, so you can apply a random password method in C # to PowerShell.
Small knitting before looking at the System.Web.Security namespace, found that there is a membership class below, there is a static method Generatepassword (), use it to generate random passwords.
Refer to MSDN URL: http://msdn.microsoft.com/en-us/library/system.web.security.membership.generatepassword.aspx
Look at the prototype of this function:
Copy Code code as follows:
public static string Generatepassword (
int length,
int Numberofnonalphanumericcharacters
)
Length: The number of digits representing the random password to be generated;
Numberofnonalphanumericcharacters: The number of non-numeric and alphabetic symbols (such as!@#$%, etc.) to be included at least.
If we use the following statement: System.Web.Security.Membership.GeneratePassword (10,2), that generates 10-bit random passwords, and at least two digits are non-numeric and alphabetic.
If we move it into the PowerShell environment, it becomes:
Copy Code code as follows:
#先进行引用
$Assembly = Add-type-assemblyname system.web
#调用类下面的静态函数
[System.web.security.membership]::generatepassword (10,2)
OK, about PowerShell generate random passwords, small knitting is thought so much.