PowerShell method of generating random cipher _powershell

Source: Internet
Author: User
Tags numeric

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.