The goal of this post is to show you how you can use Windows PowerShell to call .NET Method().
Simply, all you have to know is the namespace, assembly name, and the method name.
So, how can I do that ?!
In the following example I'll use Membership.GeneratePassword Method to generate a Complex Passwords randomly
# namespace: System.Web.Security # assembly: System.Web (in System.Web.dll) # method: GeneratePassword(int length, int numberOfNonAlphanumericCharacters)
#Load "System.Web" assembly in PowerShell console [Reflection.Assembly]::LoadWithPartialName("System.Web") #Calling GeneratePassword Method [System.Web.Security.Membership]::GeneratePassword(10,0)
Regards Sherif Talaat (Twitter: @Sheriftalaat)
That's very nice!
I like to have a selection uf passwords, so I do this:
1..10 |%{[System.Web.Security.Membership]::GeneratePassword(10,0)}
Karl
NOTE: To stop randomly falling foul of the strong passwords law use a positive integer in position number 2 of the function call. For example: 16,2 .
This is great, How can I assign that exact generated password? i.e $AccountPass=[Random Password here]
$AccountPass = $([System.Web.Security.Membership]::GeneratePassword(16,8))
Worked for me :)